4

私はさまざまな電話解像度に対して非常に柔軟にするつもりのアンドロイドのダイアログボックスに取り組んでいます。したがって、xml ファイルを作成するときに layout_weight 属性を使用しています。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/newGame_linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_weight="3"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/newGame_InvitedPlayers"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@color/ListView_Background"
            android:cacheColorHint="#00000000" >
        </ListView>

        <ListView
            android:id="@+id/newGame_Plugins"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@color/ListView_Background"
            android:cacheColorHint="#00000000" >
        </ListView>
    </LinearLayout>

    <Button
        android:id="@+id/newGame_sendInvite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Invite Players" />

    <TextView
        android:id="@+id/newGame_textViewOnlinePlayers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Online Players:" />

    <ListView
        android:id="@+id/newGame_onlinePlayers"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="5dp"
        android:layout_weight="2"
        android:background="@color/ListView_Background"
        android:cacheColorHint="#00000000" >
    </ListView>

</LinearLayout>

これがどのように見えるかです:

望ましい結果

そして確かに、それは私が望んでいるように見えます。

しかし、一番下のリストビューのアイテムをクリックすると、一番下のリストビューからアイテムが削除され、左上のリストビューに追加されます。一番下のリストビューは、最後のアイテムを削除するまでサイズが小さくなり、完全に消えて次のようになります。

現在の結果

サイズが変わらないようにしたいです。空いてる時も。

dp は非常に柔軟なサイズ単位ですが、この場合は使用したくありません。上部の 2 つの ListView は画面の 3/5 を占め、下部の ListView は残りの 2/5 を取得し、Button とTextView の間のスペースはできるだけ少なくする必要があります。

最後の Listviews の高さを match_parent に変更しようとしましたが、何も変わりません。アイテムをクリックすると、リストビューが消えます。

4

1 に答える 1

0

最後の ListView の高さを修正し、左右の ListViews 親のレイアウトに android:layout_weight="1" を配置します

于 2013-03-08T22:16:25.277 に答える