2017-09-23 100 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的圖像/字體大小的大小(如上面的代碼所示)。