向上和向下滚动后无法隐藏视图

时间:2016-09-09 09:54:23

标签: android xml android-layout android-studio android-coordinatorlayout

<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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">    

        <include layout="@layout/custom_toolbar"></include>
        <!--    
            <com.isseiaoki.simplecropview.CropImageView xmlns:custom="http://schemas.android.com/apk/res-auto"
                android:id="@+id/cropImageView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".5"
                android:background="@color/black"
                android:paddingBottom="16dp"
                android:paddingLeft="16dp"
                android:paddingRight="16dp"
                android:paddingTop="16dp"
                custom:scv_crop_mode="fit_image"
                custom:scv_frame_color="@color/app_color"
                custom:scv_frame_stroke_weight="1dp"
                custom:scv_guide_color="@color/app_color"
                custom:scv_guide_show_mode="show_always"
                custom:scv_guide_stroke_weight="1dp"
                custom:scv_handle_color="@color/app_color"
                custom:scv_handle_show_mode="show_always"
                custom:scv_handle_size="14dp"
                custom:scv_min_frame_size="50dp"
                custom:scv_overlay_color="@color/overlay"
                custom:scv_touch_padding="8dp" />

            <Button
                android:id="@+id/btn_save"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".1"
                android:onClick="saveCropImage"
                android:text="Save" />   

            <Button
                android:id="@+id/btn_choose"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".1"
                android:onClick="saveCropImage"
                android:text="choose" />    

            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".4"></View>-->

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.01"></View>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.98"
            android:orientation="horizontal">    

            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.02"></View>    

            <!--............scroll............-->

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.96"
                android:background="@drawable/border_layout"
                android:orientation="vertical">

                <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:fillViewport="true"
                    android:orientation="vertical"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior">

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/text_size_small"></View>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/logo_height"
                            android:gravity="center"
                            android:orientation="horizontal">

                            <LinearLayout
                                android:id="@+id/ll_profile"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_gravity="center">    
                                <de.hdodenhof.circleimageview.CircleImageView
                                    android:id="@+id/img_profile"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_gravity="center"
                                    android:scaleType="centerCrop"
                                    android:src="@drawable/profile_img"></de.hdodenhof.circleimageview.CircleImageView>
                            </LinearLayout>

                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/text_size_small"></View>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="?android:attr/actionBarSize"
                            android:orientation="horizontal">    

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>

                            <TextView
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_gravity="center"
                                android:layout_weight="0.15"
                                android:gravity="center|left"
                                android:text="@string/txt_name"
                                android:textColor="@color/black"
                                android:textSize="@dimen/text_size_normal" />

                            <EditText
                                android:id="@+id/edit_name"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75"
                                android:background="@null"
                                android:gravity="center|left"
                                android:singleLine="true"
                                android:text=""
                                android:textColor="@color/black"
                                android:textSize="@dimen/text_size_normal" />

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>    

                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1px"
                            android:background="@color/black"></View>    

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="?android:attr/actionBarSize"
                            android:orientation="horizontal">

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>

                            <TextView
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_gravity="center"
                                android:layout_weight="0.15"
                                android:gravity="center|left"
                                android:text="@string/txt_code"
                                android:textColor="@color/black"
                                android:textSize="@dimen/text_size_normal" />

                            <Spinner
                                android:id="@+id/spinner_counter_code"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75"
                                android:background="@drawable/spinner_register_border"
                                android:gravity="center|left"
                                android:textColor="@color/white"
                                android:textSize="@dimen/text_size_medium" />

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>    

                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1px"
                            android:background="@color/black"></View>    

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="?android:attr/actionBarSize"
                            android:orientation="horizontal">

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>

                            <TextView
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_gravity="center"
                                android:layout_weight="0.15"
                                android:gravity="center|left"
                                android:text="@string/txt_phone"
                                android:textColor="@color/black"
                                android:textSize="@dimen/text_size_normal" />

                            <EditText
                                android:id="@+id/edit_phone"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75"
                                android:background="@null"
                                android:gravity="center|left"
                                android:inputType="number"
                                android:maxLength="10"
                                android:text=""
                                android:textColor="@color/black"
                                android:textSize="@dimen/text_size_normal" />

                            <View
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.05"></View>

                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/text_size_medium"></View>

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="bottom">

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentBottom="true"
                                android:orientation="vertical">

                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1px"
                                    android:background="@color/black"></View>

                                <Button
                                    android:id="@+id/btn_done"
                                    android:layout_width="match_parent"
                                    android:layout_height="0dp"
                                    android:layout_weight="0.1"
                                    android:background="@null"
                                    android:text="Done"
                                    android:textColor="@color/app_color"
                                    android:textSize="@dimen/text_size_normal" />
                            </LinearLayout>
                        </RelativeLayout>    
                    </LinearLayout>    

                </ScrollView>
            </LinearLayout>

            <!--.............scroll end........-->

            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.02"></View>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.01"></View>
    </LinearLayout>

    <LinearLayout
        android:layout_width="@dimen/add_width"
        android:layout_height="@dimen/add_width"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_anchor="@id/ll_profile"
        app:layout_anchorGravity="center|end">

        <ImageView
            android:id="@+id/ll_pic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@mipmap/add_image" />
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

我的输出链接: - https://www.dropbox.com/s/dm38hs4f7u9y4hl/device-2016-09-09-151056.png?dl=0

滚动后

: - https://www.dropbox.com/s/9xsivx3ycdhzbtm/device-2016-09-09-151152.png?dl=0

请建议......会有很大的帮助。

1 个答案:

答案 0 :(得分:0)

有很多可能的解决方案,但我使用了这个

首先,我将所有内容都移到了ScrollView和java

之下
  public class #Activity extends #Activity implements View.OnTouchListener {

   ...
  enter code here


  ScrollView scrollView = (ScrollView) view.findViewById(R.id.scroll);
  scrollView.setOnTouchListener(this);

并实施了onTouch回调

 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {

   switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Toast.makeText(appInstance, "Down", Toast.LENGTH_LONG).show();
            return true;
        case MotionEvent.ACTION_UP:
            Toast.makeText(appInstance, "Up", Toast.LENGTH_LONG).show();
            break;
    }

    return true;
}

使用此功能时可能会出现问题,请参阅thisthis

希望这有帮助