2012-01-01 20 views
2

リストビューまたはテーブルビューを2/3の画面に配置したい場合は、リストビューのすぐ下の中央に巨大なボタンが表示されます。今問題は、リストビューが画面全体の高さを占めることです。私は、グラフィックレイアウト上の高さを調整することができませんでした。私はわずか5項目の高さのサイズを取ってみたいと思います。垂直のLinearLayoutがあなたのために、より良い仕事と同じよう下にあなたがあなたの質問に言ったことからAndroidレイアウトリストビューの高さ調整relativelayout

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/relativeLayout" 
    android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android"> 
<ListView android:layout_height="wrap_content" 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true"></ListView> 

</RelativeLayout> 

答えて

3

、画面上のボタンの中心になり、それが聞こえます。 このようにして、ListViewは、トップレベルのLinearLayoutの内部に2つのビューを配置し、画面上にビューを分散させるためにウェイトを使用して、画面の3分の2を占めるようにすることができます。例えば

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
    <ListView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="2" > 
    </ListView> 
    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" > 
     <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true"/> 
    </RelativeLayout> 
</LinearLayout> 
+0

アンドロイド:layout_alignParentBottom属性は、ボタンの下に隠されたいくつかのリスト項目を引き起こす可能性があります。 – mvsagar

4
<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/relativeLayout" 
     android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android"> 

<ListView android:layout_height="fill_parent" 
     android:id="@+id/listView1" 
     android:layout_above="@+id/button1" 
     android:layout_width="fill_parent"></ListView> 

<Button android:layout_height="wrap_content" 
     android:id="@+id/button1" 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent"></Button > 

    </RelativeLayout> 
+0

+1この方法では、まだRelativeLayoutを使用して保存 – superjos

+0

これは私のために働いた。ありがとう。しかし、私は、アンドロイド:layout_aboveに加えて属性android:layout_belowを使用して、アプリケーション内の2つの他のビューの間にリストビューがあることを確認しなければなりませんでした。 – mvsagar

関連する問題