1

レイアウトがあり、コンポーネントが画面の残りの部分を埋めるようにします(ウェイトを使用)。リストビューは完全に機能します。

最後の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="fill_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listMessages_messages"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="5dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip"
            android:layout_weight="1"
            android:background="#000000" >
        </ListView>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="50"
                android:visibility="invisible" />

            <Button
                android:id="@+id/btnNewConversation_message"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="50"
                android:onClick="newConversation"
                android:text="@string/NewConversation" />
        </LinearLayout>

    </LinearLayout>
4

2 に答える 2

1

このコードを確認してください。警告が表示されない

<?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="fill_parent"
    android:orientation="vertical"
    android:weightSum="10">
    <ListView android:id="@+id/listMessages_messages"
        android:layout_width="fill_parent" android:layout_height="0px"
        android:layout_marginBottom="5dip" android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip" android:layout_marginTop="10dip"
        android:layout_weight="8" android:background="#000000">
    </ListView>
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="0px" android:orientation="horizontal"
        android:weightSum="10" android:layout_weight="2">
        <Button android:layout_width="0px"
            android:layout_height="wrap_content" android:layout_weight="5"
             />
        <Button android:id="@+id/btnNewConversation_message"
            android:layout_width="0px" android:layout_height="wrap_content"
            android:layout_marginRight="5dip" android:layout_weight="5"
            android:onClick="newConversation"  />
    </LinearLayout>
</LinearLayout> 

両方のビューを配置するとき1.リストビュー2.線形レイアウト(2つのボタン)適切に調整するために重みプロパティを指定する必要があります。ボタンの水平分割では、2番目の線形レイアウトに重み合計プロパティを指定して重みを使用して均等に分割します。2番目の線形レイアウト内でボタンの幅を0pxに使用したことに注意してください

于 2012-03-14T11:35:22.690 に答える
0

私があなたの質問を正しく理解した場合、以下はsolです:(たとえば10)トップレイアウトでListViewに5または6のような重みを与える0pxに設定するレイアウトの高さプロパティが子を作成する線形レイアウトが残りの重みを与えることを確認してください(つまり10リストビューの重み)as layout_weight to子レイアウトfor子レイアウトlayout_heightは0pxであり、このレイアウトでは2つのボタンが配置されます。これが必要なものであることを願っています。

于 2012-03-14T10:58:03.163 に答える