【问题标题】:Theme.Dialog view size problemsTheme.Dialog 视图大小问题
【发布时间】:2010-09-10 04:11:59
【问题描述】:

我正在尝试使用主题为 Theme.Dialog 的活动创建一个基本的 AlertDialog。但是,我对对话框的大小有疑问。我的 XML 目前是这样的:

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow>
            <View
                android:background="@drawable/divider_gradient"
                android:layout_width="fill_parent"
                android:layout_height="1dip" />
        </TableRow>
        <TableRow>
            <TextView
                android:id="@+id/message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="8dip" />
        </TableRow>
    </TableLayout>
</LinearLayout>

我想要的是在标题和消息之间有一个水平条。但是,该栏未正确调整大小。该条不是活动的宽度,而是消息文本的宽度。这意味着如果活动正在被消息扩展,那么栏将填满整个活动,因此它看起来是正确的。但是,如果消息宽度小于 Activity 宽度,则该栏仅显示在带有文本的 Activity 部分的上方。我已经尝试了我能想到的“fill_parent”和“wrap_content”的每一个组合,但没有一个有效。

我也尝试过使用 RelativeLayout 并将栏放在消息文本上方,但这也不起作用。如果我使用RelativeLayout 方法并将bar 设置为fill_parent,它会导致活动扩展以填充整个屏幕宽度,这也是不可取的。理想情况下,我希望放置文本,计算活动宽度,并将条调整为该宽度(不影响它)。是否有某种方法可以标记视图以填充父视图但不影响其大小? 谢谢。

【问题讨论】:

    标签: android dialog themes android-activity


    【解决方案1】:

    您可以返回相对布局,只需在其上添加任何您想要的填充,这样当您说 fill_parent 时它不会填满屏幕。 android:padding="25dip" 作为相对布局的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      相关资源
      最近更新 更多