我不明白如何使用这个属性。谁能多告诉我一点吗?
当前回答
附加:
对于垂直方向,不要忘记设置高度为0dp
android:layout_height="0dp"
对于水平方向,不要忘记设置宽度为0dp
android:layout_width="0dp"
其他回答
顾名思义,布局权重指定了特定字段或小部件应该占据屏幕空间的数量或百分比。 如果我们在水平方向上指定权重,那么我们必须指定layout_width = 0px。 类似地,如果我们在垂直方向上指定权重,那么我们必须指定layout_height = 0px。
请查看LinearLayout的weightSum和每个视图的layout_weight。android:weightSum="4" android:layout_weight="2" android:layout_weight="2"他们的layout_height都是0px,但我不确定这是相关的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4">
<fragment android:name="com.example.SettingFragment"
android:id="@+id/settingFragment"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="2"
/>
<Button
android:id="@+id/dummy_button"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="2"
android:text="DUMMY"
/>
</LinearLayout>
除了其他答案之外,最重要的是将布局宽度(或高度)设置为0px
android:layout_width="0px"
否则你会看到垃圾
附加:
对于垂直方向,不要忘记设置高度为0dp
android:layout_height="0dp"
对于水平方向,不要忘记设置宽度为0dp
android:layout_width="0dp"
http://developer.android.com/guide/topics/ui/layout-objects.html#linearlayout
Layout_weight定义了控件相对于其他控件必须获得的空间大小。
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。