簡體   English   中英

如何在片段中為LinearLayout使用CoordinatorLayout?

[英]How to use CoordinatorLayout for LinearLayout in fragment?

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="center"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/imgViewAccount"
            android:layout_width="100dp"
            android:layout_height="100dp" />
        <TextView
            android:id="@+id/txtTitleAccount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/txtSubTitleAccount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <ListView
        android:id="@+id/lstMoreSettingsAccount"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>

我想要listview.scrollchanged向下-> linearLayout不可見,而listview向上-> linearLayout可見。 怎么做?

用這個

listView.setOnTouchListener(new View.OnTouchListener() {
        float height;
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            float height = event.getY();
            if(action == MotionEvent.ACTION_DOWN){
                this.height = height;
            }else if(action == MotionEvent.ACTION_UP){
                if(this.height < height){
                    linearLayout.setVisibility(View.VISIBLE);
                    Log.v(TAG, "Scrolled up");
                }else if(this.height > height){
                    linearLayout.setVisibility(View.GONE);
                    Log.v(TAG, "Scrolled down");
                }
            }
            return false;
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM