android 根據滑動隱藏或顯示導航 類似手機QQ好友個人資訊

來源:互聯網
上載者:User

標籤:

//重寫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);    }    @Override    protected 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控制項

 <你的項目路徑.NotifyingScrollView            android:id="@id/sv_personal"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:background="@color/layout_bg"            android:scrollbars="none" >     <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:background="@color/layout_bg"                android:orientation="vertical" >你要顯示的內容</LinearLayout>        </你的項目路徑.NotifyingScrollView>
View Code

activity使用引用

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);//導航控制項linar_top.setAlpha(ratio* 255);}};
View Code

 int Height=Utility.dip2px(context, 130); 130為要滑動的高度

android 根據滑動隱藏或顯示導航 類似手機QQ好友個人資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.