2016-04-01 14 views
0

私のアクティビティのXMLファイルはrootviewとしてScrollViewです。子として相対レイアウトが2つあります。これは私にエラーを与えている。スクロールバーを2つの子レイアウトを持つレイアウトにアサインする

私はこのXMLのScrollViewに子ビューとして2つの相対レイアウトを残したいと思います。私はそれが全体のレイアウトや、単に第2のレイアウトのいずれかスクロールできるようにしたい

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 

    <RelativeLayout 
     android:id="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:background="@drawable/bg_about"> 

     <TextView 
      android:id="@+id/textAboutUs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:layout_gravity="center" 
      android:gravity="clip_vertical" 
      android:text="@string/about_us" 
      android:textColor="#ffffff" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/relativeLayout" 
     android:layout_weight="0.96" 
     android:background="#E8E9EA" /> 
    </RelativeLayout> 

</ScrollView> 

は、ここに私のXMLファイルです。

+0

レイアウトあなたが提供している:以下全部がスクロール可能であることの例がある - いずれかの方法で、あなたはScrollView(多くの子要素を持つことができ、この子要素)のためにのみONE子要素が存在することを確認する必要があります完全に間違って書かれている。多くの欠落したパラメータがあります。なぜあなたはあなたの必要なものを教えてくれないのですか?あなたのレイアウトはどうですか?私はあなたがそれを作るのを手伝ってくれるでしょう。 –

+0

ScrollViewごとに1つ以上の子を持つことはできません。子孫は多く、子は1つしか持てません。私の答えを参照してください – blueprintChris

答えて

0

ScrollView(またはそのようにしたい場合はHorizontalScrollView)にレイアウトをラップするか、ScrollViewをルートに配置する場合は、コードの先頭に配置します。

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

    <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" 
      android:weightSum="1"> 

      <RelativeLayout 
       android:id="@+id/relativeLayout" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:background="@drawable/bg_about"> 

       <TextView 
        android:id="@+id/textAboutUs" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_gravity="center" 
        android:gravity="clip_vertical" 
        android:text="@string/about_us" 
        android:textColor="#ffffff" /> 
      </RelativeLayout> 

     </RelativeLayout> 

     </LinearLayout> 

    </ScrollView> 
+0

私はそれが私の要件に一致するかどうかを試してみます。ありがとうございました。 –

+0

@sharadchauhanそれはScrollViewsが1つ以上の子を持つことができないからです。 LinearLayoutなどの別のレイアウトで子供をラップすると、問題は解決されます。私の編集を見てください – blueprintChris

関連する問題