如果内容的高度等于屏幕高度,则ScrollView不会滚动

时间:2017-02-13 12:55:53

标签: android android-scrollview fresco

enter image description here

我遇到一个奇怪的问题,这个屏幕不可滚动。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_add_photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:background="#262626"
    tools:context="com.galleri5.android.activities.AddPhotoActivity">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="12dp"
        android:layout_marginTop="20dp"
        android:animateLayoutChanges="true">

        <TextView
            android:id="@+id/title"
            fontPath="fonts/OpenSans-Bold.ttf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/crossButton"
            android:layout_toStartOf="@+id/crossButton"
            android:animateLayoutChanges="true"
            android:maxLines="1"
            android:text="Add Photo"
            android:textColor="#F0F0E9"
            android:textSize="20sp"
            tools:ignore="MissingPrefix" />

        <ImageView
            android:id="@+id/crossButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:animateLayoutChanges="true"
            android:paddingEnd="12dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingStart="12dp"
            android:src="@drawable/ic_cross_white_large" />

    </RelativeLayout>

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/header"
        android:layout_marginEnd="12dp"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:layout_marginStart="12dp"
        android:animateLayoutChanges="true">

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

            <RelativeLayout
                android:id="@+id/imageContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:animateLayoutChanges="true">

                <com.facebook.drawee.view.SimpleDraweeView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="true"
                    fresco:actualImageScaleType="centerCrop"
                    fresco:placeholderImage="@color/wait_color"
                    fresco:placeholderImageScaleType="centerCrop"
                    fresco:roundBottomLeft="false"
                    fresco:roundBottomRight="false"
                    fresco:roundTopLeft="true"
                    fresco:roundTopRight="true"
                    fresco:roundedCornerRadius="3dp" />

            </RelativeLayout>

            <LinearLayout
                android:id="@+id/metaContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:animateLayoutChanges="true"
                android:background="#424447"
                android:orientation="vertical">

                <RelativeLayout
                    android:id="@+id/locationContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="12dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginStart="12dp"
                    android:animateLayoutChanges="true">

                    <LinearLayout
                        android:id="@+id/blankLocationState"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:animateLayoutChanges="true"
                        android:orientation="horizontal"
                        android:paddingBottom="16dp"
                        android:paddingTop="16dp">

                        <ImageView
                            android:id="@+id/blankLocationIcon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="4dp"
                            android:layout_marginRight="4dp"
                            android:animateLayoutChanges="true" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:animateLayoutChanges="true"
                            android:text="ADD LOCATION"
                            android:textColor="#F0F0E9"
                            android:textSize="10sp" />

                    </LinearLayout>

                    <RelativeLayout
                        android:id="@+id/activeLocationState"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="20dp"
                        android:layout_marginTop="20dp"
                        android:animateLayoutChanges="true"
                        android:background="@drawable/background_edittext"
                        android:visibility="gone">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="12dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginLeft="7dp"
                            android:layout_marginRight="8dp"
                            android:layout_marginStart="7dp"
                            android:layout_marginTop="12dp"
                            android:animateLayoutChanges="true">

                            <ImageView
                                android:id="@+id/activeLocationIcon"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginEnd="4dp"
                                android:layout_marginRight="4dp"
                                android:animateLayoutChanges="true" />

                            <AutoCompleteTextView
                                android:id="@+id/placeAutoComplete"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_toEndOf="@+id/activeLocationIcon"
                                android:layout_toLeftOf="@+id/deleteAutoComplete"
                                android:layout_toRightOf="@+id/activeLocationIcon"
                                android:layout_toStartOf="@+id/deleteAutoComplete"
                                android:animateLayoutChanges="true"
                                android:background="@null"
                                android:hint="e.g. Bangalore"
                                android:textColor="#424447"
                                android:textColorHint="#8A8A8A"
                                android:textSize="14sp" />

                            <ImageView
                                android:id="@+id/deleteAutoComplete"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentEnd="true"
                                android:layout_alignParentRight="true"
                                android:animateLayoutChanges="true"
                                android:paddingLeft="8dp"
                                android:paddingStart="8dp" />

                        </RelativeLayout>

                    </RelativeLayout>

                    <LinearLayout
                        android:id="@+id/afterLocationState"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:animateLayoutChanges="true"
                        android:orientation="vertical"
                        android:visibility="gone">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="16dp"
                            android:animateLayoutChanges="true"
                            android:orientation="horizontal">

                            <ImageView
                                android:id="@+id/afterLocationIcon"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginEnd="4dp"
                                android:layout_marginRight="4dp"
                                android:animateLayoutChanges="true" />

                            <TextView
                                android:id="@+id/afterLocationText"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:animateLayoutChanges="true"
                                android:textColor="#8A8A8A"
                                android:textSize="10sp" />

                        </LinearLayout>

                        <TextView
                            android:id="@+id/afterLocationEdit"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="16dp"
                            android:layout_marginTop="12dp"
                            android:animateLayoutChanges="true"
                            android:text="EDIT"
                            android:textColor="#F0F0E9"
                            android:textSize="10sp" />

                    </LinearLayout>

                    <View
                        android:id="@+id/locationLine"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_alignParentBottom="true"
                        android:animateLayoutChanges="true"
                        android:background="#262626" />

                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/captionContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="12dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginStart="12dp"
                    android:animateLayoutChanges="true">

                    <TextView
                        android:id="@+id/beforeAddCaption"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:animateLayoutChanges="true"
                        android:paddingBottom="16dp"
                        android:paddingTop="16dp"
                        android:text="ADD A CAPTION"
                        android:textColor="#F0F0E9"
                        android:textSize="10sp" />

                    <RelativeLayout
                        android:id="@+id/activeCaptionState"
                        android:layout_width="match_parent"
                        android:layout_height="120dp"
                        android:layout_marginBottom="20dp"
                        android:animateLayoutChanges="true"
                        android:background="@drawable/background_edittext"
                        android:visibility="gone">

                        <EditText
                            android:id="@+id/activeCaptionText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="10dp"
                            android:animateLayoutChanges="true"
                            android:background="@null"
                            android:hint="Say something about the photo you uploaded…"
                            android:textColor="#424447"
                            android:textColorHint="#8A8A8A"
                            android:textSize="12sp" />

                    </RelativeLayout>

                    <LinearLayout
                        android:id="@+id/afterCaptionState"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="20dp"
                        android:layout_marginTop="12dp"
                        android:animateLayoutChanges="true"
                        android:orientation="vertical"
                        android:visibility="gone">

                        <TextView
                            android:id="@+id/afterCaptionText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="12dp"
                            android:animateLayoutChanges="true"
                            android:textColor="#F0F0E9"
                            android:textSize="12sp" />

                        <TextView
                            android:id="@+id/editCaptionButton"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:animateLayoutChanges="true"
                            android:text="EDIT"
                            android:textColor="#F0F0E9"
                            android:textSize="10sp" />

                    </LinearLayout>

                </RelativeLayout>

            </LinearLayout>

            <RelativeLayout
                android:id="@+id/nextButton"
                android:layout_width="match_parent"
                android:layout_height="32dp"
                android:layout_marginBottom="20dp"
                android:animateLayoutChanges="true"
                android:background="@drawable/button_background">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:animateLayoutChanges="true"
                    android:text="NEXT"
                    android:textColor="#F0F0E9"
                    android:textSize="10sp" />

            </RelativeLayout>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

我希望标题部分(添加照片和交叉图像)保持在顶部,其余内容可以滚动。图像显示为SimpleDraweeView。请注意,图像下方有一些元素,但我无法滚动查看它们。

2 个答案:

答案 0 :(得分:0)

尝试添加:

<ScrollView android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"  //change here
    android:fillViewport="true" >  //add this

答案 1 :(得分:0)

想出来,这是我自己的错误。我在我的活动中写过这个

scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (activeLocationState.getVisibility() == View.VISIBLE && !TextUtils.isEmpty(currentlocation)) {
                    activeLocationState.setVisibility(View.GONE);
                    afterLocationState.setVisibility(View.VISIBLE);
                    afterLocationText.setText(currentlocation);
                }

                if (activeCaptionState.getVisibility() == View.VISIBLE) {
                    currentCaption = activeCaptionText.getText().toString().trim();
                    if (!TextUtils.isEmpty(currentCaption)) {
                        activeCaptionState.setVisibility(View.GONE);
                        afterCaptionState.setVisibility(View.VISIBLE);
                        afterCaptionText.setText(currentCaption);
                    }
                }

                return true;
            }
        });

这消耗了所有触摸事件。为解决此问题,我将触控逻辑移至LinearLayout内的ScrollView