2017-08-02 24 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"に設定すると、レイアウトは常に親と同じくらい高くなり、アンドロイドはそれがすでに完全に見えるので、スクロールするものはありません。

<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"> 

変更

同じことはもちろんの水平レイアウトのために行くが、それは「wrap_content」でなければなりませんlayout_widthです。レイアウトにオリエンテーションが設定されていないので、デフォルトでは水平になります。

+0

お時間をいただきありがとうございます。私はそれをするが、何も起こらなかった... – Arshiiia13

関連する問題