2017-09-23 97 views
0

我在ScrollView中有一个RelativeLayout。但是,当它作为父布局时,ScrollView不会滚动。当ScrollView作为父布局时ScrollView不滚动

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:fillViewport="true" 
android:layout_height="match_parent" 

> 

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

    <ImageView 
     android:id="@+id/iv_about_background" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:src="@drawable/stack" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/iv_about_background" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     /> 
</RelativeLayout> 
</ScrollView> 

编辑:我取下rootView.setOnTouchListener从我的片段和ScrollView工作正常

+0

你的滚动视图结束在哪里? –

+1

https://stackoverflow.com/questions/20896963/relativelayout-inside-scrollview-not-working –

+0

@ Harshit Trivedi错过了复制时的行。问题更新 – Ameer

回答

0

尝试

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:fillViewport="false" 
android:layout_height="match_parent" 

> 

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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

       <ImageView 
        android:id="@+id/iv_about_background" 
        android:layout_width="match_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/stack" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/iv_about_background" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        /> 
     </RelativeLayout> 

    </LinearLayout> 

</ScrollView> 
+0

我试过这个。但不滚动。 – Ameer

+0

@Ameer设置RelativeLayout'android:layout_height =“match_parent”' –

+1

我的RelativeLayout高度是match_parent。我在另一个布局中尝试了ScrollView。它的作品 – Ameer

0

有几件事情,你可以做:

  1. 确保相对于布局高度内容不仅仅是父母。我认为150dp和10dp仍然低于父母身高。

  2. 将ScrollView的宽度和高度更改为fill_parent而不是match_parent,并对相对布局执行相同的操作。

  3. 添加android:scrollbars = "vertical"财产,滚动型

希望它是有益的。

+0

我试过用TextView上的大文本,它不滚动 – Ameer

0

试试这个,希望它会帮助你。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:id="@+id/iv_about_background" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/stack" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/iv_about_background" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" /> 
    </RelativeLayout> 
</LinearLayout> 

2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:fillViewport="true" 
android:layout_height="match_parent" 
> 

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

    <ImageView 
     android:id="@+id/iv_about_background" 
     android:layout_width="match_parent" 
     android:layout_height="350dp" 
     android:src="@drawable/stack" /> 



    <TextView 
     android:text="rgergijsojsoierjgoegorijtowjtojrtoihjorjthlbkmoijbrotoojgowijtogirtjhowortgjowjtgjwrtgjowrijgtoiwjt" 
     android:textSize="50sp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/iv_about_background" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     /> 

</RelativeLayout> 

我已经改变了图像的高度,大小350dp并设置文字大小50SP知道代码是否你已经发布的作品或没有。你的代码非常好,但是你必须在scrollview中添加更多的视图,或者增加textview的图像/字体大小的大小(如上面的代码所示)。