android 根据滑动隐藏或显示导航 类似手机QQ好友个人信息
生活随笔
收集整理的這篇文章主要介紹了
android 根据滑动隐藏或显示导航 类似手机QQ好友个人信息
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//重寫ScrollViewpublic class NotifyingScrollView extends ScrollView {/*** @author Cyril Mottier*/public interface OnScrollChangedListener {void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);}private OnScrollChangedListener mOnScrollChangedListener;public NotifyingScrollView(Context context) {super(context);}public NotifyingScrollView(Context context, AttributeSet attrs) {super(context, attrs);}public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@Overrideprotected void onScrollChanged(int l, int t, int oldl, int oldt) {super.onScrollChanged(l, t, oldl, oldt);if (mOnScrollChangedListener != null) {mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);}}public void setOnScrollChangedListener(OnScrollChangedListener listener) {mOnScrollChangedListener = listener;}} View Code
布局引用重寫NotifyingScrollView控件
<你的項(xiàng)目路徑.NotifyingScrollViewandroid:id="@id/sv_personal"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/layout_bg"android:scrollbars="none" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/layout_bg"android:orientation="vertical" > 你要顯示的內(nèi)容 </LinearLayout></你的項(xiàng)目路徑.NotifyingScrollView> View Codeactivity使用引用
NotifyingScrollView sv_personal=(NotifyingScrollView)findViewById(R.id.sv_personal); sv_personal.setOnScrollChangedListener(mOnScrollChangedListener);private NotifyingScrollView.OnScrollChangedListener mOnScrollChangedListener = new NotifyingScrollView.OnScrollChangedListener() { public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { int Height=Utility.dip2px(context, 130); float ratio =Math.max(Math.min(1, t/Height), 0); //導(dǎo)航控件 linar_top.setAlpha(ratio* 255); } }; View Code?int Height=Utility.dip2px(context, 130); 130為要滑動(dòng)的高度
總結(jié)
以上是生活随笔為你收集整理的android 根据滑动隐藏或显示导航 类似手机QQ好友个人信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下C调用lua的第一个程序
- 下一篇: 第二天——hibernate讲完了