相对布局中的无效布局参数:layout_weight

fai*_*zal 4 android android-layout-weight

在 Eclipse 编辑器中,我的 android 布局文件出现以下错误:

Invalid layout param in a RelativeLayout: layout_weight
Run Code Online (Sandbox Code Playgroud)

布局 :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText
        android:id="@+id/text_input"    
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_weight="0.7"
        />

    <EditText
        android:id="@+id/text_input1"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_toRightOf="@id/text_input"
        />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的 layout_weight 有什么问题?

Bho*_*att 5

相对布局不支持 weight.

Linearlayout支持它。您可以Linearlayout像下面这样使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="Horizontal">

    <EditText
        android:id="@+id/text_input"    
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_weight="0.7"
        />

    <EditText
        android:id="@+id/text_input1"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)