我想创建一个显示视频标题和标签的对话框。下面的文字我想添加按钮查看,编辑和删除,并使这些元素相同的大小。有人知道如何修改.xml布局文件以使LinearView中的元素大小相同吗?
当前布局文件如下所示:
<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>
如果有人能通过修改粘贴的文件内容来展示解决方案,我将不胜感激。
谢谢!
发布于 2009-07-24 11:30:01
在三个Button
上使用android:layout_width="0px"
和android:layout_weight="1"
。这意味着按钮占用的空间不能超过0像素,但这三个按钮之间应该分开任何额外的空间。这应该会给你带来你想要的视觉效果。
发布于 2010-08-20 19:30:27
另一种方法是使android:layout_width="fill_parent"
和android:layout_weight="1"
,这也会很好!
发布于 2015-06-05 14:59:54
将LinearLayout与所需的weightSum一起使用,并使用相等的layout_weight创建元素。这里有一个例子..。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_share_white_36dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_search_white_36dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_event_note_white_36dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_brush_white_36dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_menu_white_36dp"/>
</LinearLayout>
所以,所有元素的权重和是5。这是屏幕截图…
请注意,使用的是Google Material Design图标。希望这能对你有所帮助。
https://stackoverflow.com/questions/1177020
复制相似问题