【发布时间】:2013-06-24 04:58:01
【问题描述】:
这是我的自定义对话框,有一些文本框和两个按钮。 我在它上面使用了一个RelativeLayout。
我希望对话框大小与内容相匹配,而不是下面的所有空白区域。 我不想使用明确的像素高度(这不是一个好习惯)。
另外,有办法在每个视图之间留出一些空间吗?
这是我的 XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:textStyle="italic" />
<TextView
android:id="@+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="@+id/txt_desc"
android:textSize="8pt" />
<TextView
android:id="@+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="@+id/txt_date"
android:textSize="8pt" />
<Button
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/txt_place"
android:layout_toRightOf="@+id/view"
android:text="@string/btn_close" />
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/txt_place"
android:layout_toLeftOf="@+id/view"
android:drawableLeft="@android:drawable/ic_menu_edit"
android:text="@string/btn_edit" />
</RelativeLayout>
【问题讨论】:
-
使用 MarginTop|MarginLeft|... 作为您的第二个问题。以 dp 为单位的度量
标签: android android-layout android-relativelayout customdialog