Android:如何使 LinearLayout 中的所有元素大小相同? [英] Android: How to make all elements inside LinearLayout same size?
问题描述
我想创建一个对话框来显示视频标题和标签.在文本下方,我想添加按钮查看、编辑和删除,并使这些元素的大小相同.有谁知道如何修改 .xml 布局文件以使 LinearView 中的元素大小相同?
I would like to create a dialog to display a video title and tags. Below text I would like to add buttons View, Edit and Delete and make these elements same size. Does anyone know how to modify .xml layout file in order to make elements inside LinearView same size?
当前布局文件如下所示:
The current layout file looks like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtTitle" android:text="[Title]" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtTags"
android:text="[Tags]" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnPlay"
android:text="View">
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnEdit"
android:text="Edit">
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnDelete"
android:text="Delete">
</Button>
</LinearLayout>
</LinearLayout>
如果有人可以通过修改粘贴的文件内容来展示解决方案,我将不胜感激.
I would appreciate if anyone could show the solution by modifying the pasted file content.
谢谢!
推荐答案
在三个上使用 android:layout_width="0px"
和 android:layout_weight="1"
按钮
s.也就是说按钮不应占用超过 0 像素,但它们三个应该在它们之间分割任何额外的空间.这应该会给你你想要的视觉效果.
Use android:layout_width="0px"
and android:layout_weight="1"
on the three Button
s. That says the buttons should take up no more than 0 pixels, but the three of them should split any extra space between them. That should give you the visual effect you wish.
这篇关于Android:如何使 LinearLayout 中的所有元素大小相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!