Android layout 布局权重给出了意外的结果
所以我试着在我的屏幕上有三个部分。占据屏幕10%的顶部“工具栏”样式的东西。我稍后将填充的数据占屏幕的70%,最后占底部搜索栏屏幕的20% 我认为这将是一件简单的事情:一个线性布局,有3个线性布局子元素,它们的权重分别为0.1、0.7和0.2。然而,这是行不通的。当我更改某些视图的布局权重时,它会更改其他视图占用的屏幕数量。以下是我目前掌握的代码:Android layout 布局权重给出了意外的结果,android-layout,Android Layout,所以我试着在我的屏幕上有三个部分。占据屏幕10%的顶部“工具栏”样式的东西。我稍后将填充的数据占屏幕的70%,最后占底部搜索栏屏幕的20% 我认为这将是一件简单的事情:一个线性布局,有3个线性布局子元素,它们的权重分别为0.1、0.7和0.2。然而,这是行不通的。当我更改某些视图的布局权重时,它会更改其他视图占用的屏幕数量。以下是我目前掌握的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.95"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/transparent"
>
</LinearLayout>
</LinearLayout>
这给了我一个占屏幕20%的第一个空布局(是的,权重为0.95),第二个空布局占屏幕的80%,最终的布局是空的。当我给最终布局一个权重,比如说,0.1,它会给第一个布局更多的空间。我想我有一些流氓格式。来自:
此属性根据视图在屏幕上应占据的空间大小为视图指定“重要性”值。较大的权重值允许其展开以填充父视图中的任何剩余空间
换句话说,它表示布局可以占用的剩余空间的百分比。如果不想按这些比例分配空间,则应首先将高度0指定给
线性布局
(表示所有屏幕都是可用空间)
来自:
此属性根据视图在屏幕上应占据的空间大小为视图指定“重要性”值。较大的权重值允许其展开以填充父视图中的任何剩余空间
换句话说,它表示布局可以占用的剩余空间的百分比。如果不想按这些比例分配空间,则应首先将高度0指定给
线性布局
(表示所有屏幕都是可用空间)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:background="@android:color/transparent">
</LinearLayout>
</LinearLayout>