2

リストビューとリストビューの下のボタンを含むカスタム ダイアログを作成したいと考えています。ボタンはリストビューの下にある必要がありますが、常に表示されます (layout_alignParentBottom="true")。

非常にうまく機能するxmlを作成しましたが、長いリストに対してのみです。リストが短い場合、ボタンは依然として画面の下部にあり、ダイアログ タイトルの高さは引き伸ばされて、ダイアログが画面いっぱいに表示されます。添付の画像は、私が今日得たものを示しています。

要するに。必要な場合にのみ画面を埋める通常のダイアログが必要です。

何らかの理由で xml を投稿できません。ボタンは親の下に配置され、ボタンの上に小さなパネルが配置され、このパネルの上にリストビューが配置されます。すべてのレイアウトは、layout:height=wrap_content です。

助けてくれてありがとう。/マグナス

代替テキスト

4

3 に答える 3

6

この答えは一般的に正しいですが、ネストされたレイアウトが多いため、かなりのオーバーヘッドが発生します。

必要なのはLinearLayout、特定の構成を持つ単純なものです。

<ListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     />
<!-- Notice layout_weight=1 and height=0dp - it's the most important thing here-->


<WhateverLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
<!-- And the layout below the listview has some arbitrary height (but no weight!)-->

</WhateverLayout>

</LinearLayout>

結果は同じです。「コンテンツよりも大きくなく、最大で画面と同じ大きさのダイアログで、常にボタンが表示されます。」

于 2013-08-06T18:48:06.607 に答える
3

問題は解決された。

Android ソース コードからalert_dialog.xmlを取得し、少し変更しました。リストビューを customPanel フレームレイアウトに追加し、topPanel と contentPanel を削除しました。

結果: コンテンツより大きくなく、最大で画面と同じ大きさのダイアログで、常にボタンが表示されます。

于 2011-01-14T13:42:11.277 に答える
1

@Fresh_Meatへの回答

次のようにリストビューの下部にボタンを追加できます: http://www.anddev.org/code-snippets-for-android-f33/listview-with-a-footer-item-t49281.html

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="10dip"
   >
    <LinearLayout
        android:id="@+id/bottom_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
            <!--Put whatever view item you want here -->
            <EditText
             android:id="@+id/conversation_reply"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="write a reply..."
             />
   </LinearLayout>
   <ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"
    android:layout_above="@id/bottom_view"
    />
</RelativeLayout>

フッター付きリスト

アラート ビュー内でこれを使用します

于 2011-02-22T14:36:29.520 に答える