滚动型不滚动,如果内容的高度等于屏幕高度

问题描述:

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。请注意,图片下方有一些元素,但我无法滚动查看它们。

+0

任何人都有任何想法为什么发生这种情况,以及如何解决它? –

尝试添加:

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

它没有工作。 –

+0

尝试在'linearlayout'里面包裹scrollview .. – rafsanahmad007

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

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