这。我不明白为什么第一个布局看起来比第二个布局更大,如果最后一个布局有.6 (60%)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".4" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".6">
</RelativeLayout>
</LinearLayout>发布于 2017-01-17 12:18:43
@Miguel Barra适用于此
android:layout_width="match_parent"替换为
android:layout_width="wrap_content"或
android:layout_width="0dp"在这两个相对布局中
发布于 2017-01-17 12:19:17
老实说,我没有尝试过分数权重值,但理论上它们应该是有效的。但我认为这里的问题是,您需要将这两个相对布局的layout_width设置为0dp。只有这样,权重参数才会生效。试试看。来自android文档-
要创建每个子级使用相同屏幕空间的线性布局,请将每个视图的android:layout_height设置为"0dp“(对于垂直布局)或将每个视图的android:layout_width设置为"0dp”(对于水平布局)。然后将每个视图的android:layout_weight设置为“1”。
发布于 2017-01-17 12:21:01
你应该拿着这个。
如果使用权重,则有两种情况
情况1:如果你有水平的父级。你应该有layout_width="0dp“
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".6" >
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".4">
</RelativeLayout>
</LinearLayout>案例1:如果你有垂直的父级。你应该有layout_height="0dp“
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4">
</RelativeLayout>
</LinearLayout>https://stackoverflow.com/questions/41688963
复制相似问题