Chr*_*ris 3 android relativelayout android-linearlayout
也许我误解了layout_weight参数,但我无法理解为什么这样的东西不起作用......
<?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="horizontal" android:weightSum="1">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="TextView"
android:background="@color/apr_brightyellow"/>
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="TextView"
android:background="@color/apr_yellow"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在LinearLayout中有三个或更多文本视图.我想将它们放在宽度为百分比的列中.这就是它产生的东西:
layout_weight设置为0.3/0.2/0.5

然后我改变了layout_weight参数,如下所示:
<?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="horizontal" android:weightSum="1">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="TextView"
android:background="@color/apr_brightyellow"/>
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="TextView"
android:background="@color/apr_yellow"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在我按照自己的意愿得到它:
layout_weight设置为0.3/0.2/0.5

它是一个错误还是我真的误解了layout_weight的全部内容?
Ale*_*nko 12
当你使用时,android:layout_weight你应该设置android:layout_width="0dp"(如果垂直方向 - android:layout_height="0dp").
| 归档时间: |
|
| 查看次数: |
6080 次 |
| 最近记录: |