2016-07-15 4 views
1

要素が少なくてもレイアウトを垂直方向に中央に配置したい場合は、左側の画像を参照してください。多くの要素がある場合、私はそれが成長し、画面全体をカバーするスクロールビューになりたい。右の画像を参照してください。中心のスクロールビューは、要素数が少なく、親が多くなると垂直に表示されます

どうすればこの問題を解決できますか?

enter image description here

赤色要素が動的レイアウトに追加されます。青色の2つのTextViewはスクロールビューの外側にあります。基本的に、スクロールビューは、画面にスペースが残っていないときに起動します。

+0

私はあなたが重力= center_verticalでのLinearLayout内のヘッダーとフッターとリストビューを使用することをお勧めします。 – rajesh

答えて

0

これを試してください。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#fff"> 

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#ff0000" 
     android:gravity="center" 
     android:padding="5dp" 
     android:text="Top TextView" 
     android:textColor="#fff" /> 

    <!-- You can remove min Height if you don't want it--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#00ffff" 
     android:minHeight="100dp"> 

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

      <!-- Do you Code here.--> 

     </ScrollView> 
    </LinearLayout> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#ff0000" 
     android:gravity="center" 
     android:padding="5dp" 
     android:text="Bottom TextView" 
     android:textColor="#fff" /> 

</LinearLayout> 

+0

アンディありがとう!これは私が探していたものだった。ただし、ScrollViewを含むLinearLayoutをlayout_width = 0およびlayout_weight = 1に変更する必要がありました。 –

+0

ようこそjens :) –

関連する問題