2011-10-28 7 views
0

私はAndroidを初めて使っているので、まだGUiレイアウトではあまりよくありません。私は自分のアプリのためのGUIを構築しているだけで、私が望むように動作することはできません。必要なのは、画面の下部にある4つのボタンが水平に積み重ねられていることです。ボタンの上には、画面の残りの部分を埋めるSurfaceViewを配置しました。Android - GUIレイアウト

----------------- 
- SurfaceView - 
----------------- 
--- --- --- --- 
-B- -B- -B- -B- 
--- --- --- --- 
:残念ながら、このようなものになり

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 
      <SurfaceView 
       android:id="@+id/surfaceView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
     </TableRow> 
     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 
      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
       <Button 
        android:id="@+id/button2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
      </LinearLayout> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

:私が得たclosesetはこのだった

----------------- 
-    - 
-    - 
-    - 
-    - 
- SurfaceView - 
-    - 
-    - 
-    - 
----------------- 
--- --- --- --- 
-B- -B- -B- -B- 
--- --- --- --- 

:結果はこのような何か(私はこれが明らかであると思います)でなければなりません

答えて

2
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


      <SurfaceView 
       android:id="@+id/surfaceView1" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight = "1" 
      /> 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
       <Button 
        android:id="@+id/button2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
      </LinearLayout> 

</LinearLayout> 

これを試してください。

layout_weightは、線形レイアウトの子に作用するタグです。子供が言及されている場合は、体重に応じて向きの測定値を共有します。あなたの場合、線形レイアウトは垂直なので、重量が言及されていれば高さを共有します。

デフォルトweightSumのlinearLayoutは1です。したがって、1つの子供に1を与えると、残りのスペースが必要になります。そして、親に2人の子供がおり、その体重が0.6と0.4であるとすると、最初の子供は親の高さの60%を占め、残りの子供は2番目の子供によって40%を占めるとします。

+0

ありがとうございました。私はウェブサイトが私にできるようになるとすぐにこれを受け入れます。これらの属性の使い方を説明してください:android:layout_height = "0dp" android:layout_weight = "1" – Yoav

+1

私の編集した回答をチェックしてください。 –

+0

ありがとうございました.12 – Yoav

0

一番上のレイアウトに相対レイアウトを使用し、ボタンバーレイアウトにalignParentBottomを使用してみます。

関連する問題