2017-08-02 41 views
0

我想讓可滾動佈局,因爲我的TextView有長文本。我搜索並找到了一些解決方案,例如在我的RelativeLayout中創建一個ScrollView,並在那裏創建另一個RelativeLayout。並像這樣改變了我的xml代碼。但沒有發生。如何使RelativeLayout可滾動?

這是我的XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.arsh.fina.IntroActivity"> 

    <include layout="@layout/content"/> 

    <ScrollView 
     android:layout_marginTop="55dp" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="55dp"> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="13dp" 
      android:adjustViewBounds="true" 
      app:srcCompat="@drawable/surv1" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" /> 


     <TextView 
      android:layout_below="@+id/imageView3" 
      android:layout_marginTop="20dp" 
      android:textColor="#FFFFFF" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="A VERY 
VERY 
VERy 
VERY TEXT"/> 


    </RelativeLayout> 

</ScrollView> 

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/a1" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="55dp"> 


    <android.support.design.widget.NavigationView 
     android:id="@+id/a2" 
     android:layout_gravity="right" 
     android:layout_height="match_parent" 
     android:layout_width="180dp" 
     app:headerLayout="@layout/header" 
     app:menu="@menu/drawer"/> 
</android.support.v4.widget.DrawerLayout> 

</RelativeLayout> 

我在哪裏去了?

回答

1

爲了使垂直佈局可以滾動,其layout_height必須是「wrap_content」。如果將其設置爲「match_parent」,則佈局將始終與父級一樣高,並且不會滾動到任何內容,因爲android將會完全可見。

更改爲

<ScrollView 
    android:layout_marginTop="55dp" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="55dp"> 

這同樣適用於課程的水平佈局,但後來它的layout_width那一定是「WRAP_CONTENT」。您的佈局中沒有方向設置,因此默認情況下它會處於水平狀態。

+0

感謝您的時間。我做到了,但沒有發生任何事情...... – Arshiiia13