Theme.Dialog视图大小问题
我正在尝试使用主题为 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>
我想要的是标题和消息之间有一个水平条。但是,该栏的大小没有正确调整。条形不是活动的宽度,而是消息文本的宽度。这意味着,如果活动通过消息展开,则该栏将填充整个活动,因此看起来是正确的。但是,如果消息宽度小于活动宽度,则该栏仅显示在活动的带有文本的部分上方。我已经尝试了我能想到的“fill_parent”和“wrap_content”的每一种组合,但这些都不起作用。
我还尝试使用relativelayout并将栏放置在消息文本上方,但这也不起作用。如果我使用RelativeLayout方法并将bar设置为fill_parent,它会导致活动扩展以填充整个屏幕宽度,这也是不可取的。理想情况下,我希望放置文本,计算活动宽度,并将条形调整为该宽度(不影响它)。是否有某种方法可以标记视图以填充父视图但不影响其大小? 谢谢。
I'm trying to create a basic AlertDialog using an activity with a theme of Theme.Dialog. However, I'm having an issue with the size of the dialog. My XML is currently this:
<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>
What I want is for there to be a horizontal bar between the title and the message. However, the bar is not being resized correctly. Rather than being the width of the activity, the bar is the width of the message text. This means that if the activity is being expanded by the message, then the bar will fill the whole activity, so it looks correct. However, if the message width is less than the activity width, the bar only displays above the part of the activity with the text. I've tried every single combination of "fill_parent" and "wrap_content" that I can think of, and none of those work.
I've also tried using RelativeLayout and placing the bar above the message text, but that also doesn't work. If I use the RelativeLayout approach and set the bar to fill_parent, it causes the activity to expand to fill the whole screen width, which is also undesirable. Ideally, I want the text placed, the activity width computed, and the bar resized to that width (without affecting it). Is there some way to flag a view to fill the parent view but not to affect its size?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以返回到相对布局,然后在其上添加任何您想要的填充,这样当您说 fill_parent 时,它就不会填充屏幕。 android:padding="25dip" 作为相对布局的属性。
you can move back to relative layout and just put a padding of whatever you want on it so when you say fill_parent it doesn't fill the screen. android:padding="25dip" as an attribute for the relative layout.