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

时间:2016-06-08 04:31:48

标签: android xamarin xamarin.android

<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下去时 - &gt; linearLayout是不可见的,当listview上升时 - &gt; linearLayout是可见的。 怎么做?

1 个答案:

答案 0 :(得分:0)

使用此

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;
        }
    });