19

カスタム ダイアログ フラグメントとその xml を次のように作成しました。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"

    android:padding="5dip" >

    <ListView
        android:id="@+id/product_list"
         android:background="@drawable/border_details"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         />

    <RelativeLayout
        android:id="@+id/AddtoCart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dp"

        android:background="#005959" >

        <Button
            android:id="@+id/button_addToCart"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/gradient_button"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:text="@string/add_to_cart"
            android:textColor="#000000" />
    </RelativeLayout>

</RelativeLayout>

このダイアログを呼び出すと、スクリーンショットに示されているように全画面表示になります。

スクリーンショット

このダイアログのサイズをリストとボタンの高さに制限するにはどうすればよいですか?

余分な空白を削除するにはどうすればよいですか?

4

2 に答える 2

26

以下のようにリストを1に変更RelativeLayoutLinearLayoutて設定することで解決weight

<?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="wrap_content"
    android:layout_margin="5dp"
   android:orientation="vertical"
    android:padding="5dip" >

    <ListView
        android:id="@+id/product_list"
         android:background="@drawable/border_details"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
         />
    <RelativeLayout 
    android:id="@+id/AddtoCart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginTop="10dp"
    android:background="#005959" >

    <Button
        android:id="@+id/button_addToCart"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:background="@drawable/gradient_button"
        android:text="@string/add_to_cart"
        android:textColor="#000000" />

</RelativeLayout>
</LinearLayout>
于 2014-02-04T11:59:14.673 に答える
13

親の相対レイアウトの高さは静的ではないため、下部の相対レイアウトを指定android:layout_alignParentBottom="true" したため、画面の下部が使用されます。

解決:

  1. 下の相対レイアウトの参照を変更して、下 (下) をリスト ビューに揃えることができます。
  2. または、下部のレイアウトをリスト ビューのフッターとして設定できます
  3. または、ラップコンテンツとして高さを持つ親の相対レイアウトの代わりに、線形レイアウトの垂直を使用します
  4. または、親の相対レイアウトに静的な高さを指定して、下部の相対レイアウトが親の相対レイアウトの高さを取得し、親の相対レイアウトの下部に配置されるようにします (リスト ビューに下部の相対レイアウトの上に配置することを忘れないでください)。
于 2014-02-04T06:54:18.490 に答える