2016-03-22 13 views
-1

水平のスクロールバーを上部(ボタンを含む)に配置し、その後に相対レイアウト(その中に入れたものを含めることができます)と最後の水平スクロールバーは一番下に並んでいます。水平スクロールバーを上/下に固定し、中間の相対的なレイアウトをその間のすべてのものに強制するにはどうすればよいですか?あなたがLinearLayoutの内側layout_weightを使用することができますAndroidでこれらの3つのアイテムを配置する方法

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
    > 
    <RelativeLayout 
     android:id="@+id/top_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"></RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/bottom_container" 
     android:layout_width="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_height="wrap_content"> 
    </RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/middle_container" 
     android:layout_width="match_parent" 
     android:layout_below="@id/top_container" 
     android:layout_above="@id/bottom_container" 
     android:layout_height="match_parent"></RelativeLayout> 
</RelativeLayout> 
+0

あなたが投稿することができますのcreenshot or wireframe or code –

+0

layout_weight = "" –

+0

のように、このレイアウトのパーティションを使用することができます。内容をラップする高さを上部と下部に持たせたいが、中心の相対レイアウトはすべての間に広がるようにする。 –

答えて

0

... RelativeLayoutを使用して

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center"> 
    <RelativeLayout 
     android:id="@+id/top_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"></RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/middle_container" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"></RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/bottom_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </RelativeLayout> 
</LinearLayout> 

は....それは、レイアウトを埋めるために展開する必要があります。例えば

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 
    <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     <!-- Buttons --> 
    </HorizontalScrollView> 
    <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 
     <!-- Content --> 
    </RelativeLayout> 
    <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     <!-- More Buttons --> 
    </HorizontalScrollView> 
</LinearLayout> 
+0

'android:layout_height = "0dp"/android:layout_weight = "1" 'は私が欠けていたものです。これはmatch_parentまたはwrap_contentの使用とどのように違うのですか?どうしたの? –

+0

大丈夫ですので、上のコンテナと下のコンテナの高さはwrap_contentです。それは子ノードが必要とする高さにすぎず、中央のコンテナにweight = 1とheight = 0dpを指定すると残りの高さになります。 – Ritesh

+0

width = "0dp"とweight = "1"のようなプロパティを与えることで、幅を実現できます。 – Ritesh

0

のLinearLayoutを使って
0

私たちはより良い助けることができるようにあなたのワイヤーフレームを投稿してください。しかし、おそらくあなたのソリューションは次のようなものだと思うでしょう: - メインレイアウトをRelativeLayoutにしておきます。メインレイアウトの下に、垂直方向に別のLinearLayoutを描いてください。水平スクロールビューとその他のアイテムをLinearLayoutに配置し、 :

アンドロイド:layout_alignParentBottom = "true" を

あなたのXMLは次のようになります。

<RelativeLayout> 
    <LinearLyout> 
    // horizontal scrollview 
    // other items 
    </LinearLayout> 
    // horizaontal scrollview with alignparentbottom="true" 
</RelativeLAyout> 
関連する問題