Android 权重 属性 布局错误
Android weight property error in layout
我有 5 个水平线性布局。我在一个线性布局中对齐了三个编辑文本。我为所有编辑文本应用了权重字段 属性 1。但是在第一个和第三个线性布局中与 属性 完美配合。其他人无法正常工作。再次在第 5 个水平线性布局中有一个微调器视图,它也产生了同样的问题。然后第 4 行在水平布局中添加一个可用的线性布局,一个编辑文本和一个图像视图。它也没有正确固定重量 属性。我把布局代码放在下面。
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yellow" />
<TextView
android:id="@+id/sign_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sign Up" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/f_name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:layout_marginRight="20dp"
android:hint="First Name"
android:background="@drawable/edittext_yellow_singleline" >
</EditText>
<EditText
android:id="@+id/l_name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:layout_marginRight="20dp"
android:hint="Last Name"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:hint="Username *"
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout//this layout creating alignment issue. if I put extra space in hint nearly it was getting good view. But different screens wont work
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="12"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="phone"
android:layout_marginRight="20dp"
android:hint="Phone"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/plan_id"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Member Plan ID"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPassword"
android:hint="Password *"
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="50"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Address"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/mobile"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="10"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="phone"
android:layout_marginRight="20dp"
android:hint="Mobile * "
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textEmailAddress"
android:hint="Email * "
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="City"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/state"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="State"
android:background="@drawable/edittext_yellow_singleline" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">//tried this not worked
<EditText
android:id="@+id/dob"
android:layout_width="265dp"
android:layout_height="40dp"
android:maxLength="10"
android:textSize="18dp"
android:inputType="date"
android:hint="Date of Birth"
android:background="@drawable/edittext_yellow_singleline" />
<ImageButton
android:id="@+id/img_dob"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cal" />
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/country"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Country"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/zipcode"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="6"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="number"
android:layout_marginRight="20dp"
android:hint="Zipcode "
android:background="@drawable/edittext_yellow_singleline" />
<Spinner
android:id="@+id/gender"
android:layout_width="305dp"//finally hard coded but it wont work for multiple screens
android:layout_height="40dp"
/>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="30dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/ok"
android:layout_width="100dp"
android:layout_height="40dp"
android:gravity="center"
android:textSize="20dp"
android:text="Done"
android:background="@drawable/login_button_shape" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
如果不行,table布局会给出解决方案吗?
如果我减少提示中的文本,那么它在第二行也能正常工作。如果我提供 space 以与包含低文本的其他 edittext 字段保持相同的文本长度也不起作用。
你所有的 EditText 应该有:
android:layout_width="0dp"
所有的LinearLayout都应该有:
android:weightsum="3"
我有 5 个水平线性布局。我在一个线性布局中对齐了三个编辑文本。我为所有编辑文本应用了权重字段 属性 1。但是在第一个和第三个线性布局中与 属性 完美配合。其他人无法正常工作。再次在第 5 个水平线性布局中有一个微调器视图,它也产生了同样的问题。然后第 4 行在水平布局中添加一个可用的线性布局,一个编辑文本和一个图像视图。它也没有正确固定重量 属性。我把布局代码放在下面。
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yellow" />
<TextView
android:id="@+id/sign_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sign Up" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/f_name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:layout_marginRight="20dp"
android:hint="First Name"
android:background="@drawable/edittext_yellow_singleline" >
</EditText>
<EditText
android:id="@+id/l_name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:layout_marginRight="20dp"
android:hint="Last Name"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPersonName"
android:hint="Username *"
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout//this layout creating alignment issue. if I put extra space in hint nearly it was getting good view. But different screens wont work
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="12"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="phone"
android:layout_marginRight="20dp"
android:hint="Phone"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/plan_id"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Member Plan ID"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="20"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPassword"
android:hint="Password *"
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="50"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Address"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/mobile"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="10"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="phone"
android:layout_marginRight="20dp"
android:hint="Mobile * "
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textEmailAddress"
android:hint="Email * "
android:background="@drawable/edittext_yellow_singleline" />
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="City"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/state"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="30"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="State"
android:background="@drawable/edittext_yellow_singleline" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">//tried this not worked
<EditText
android:id="@+id/dob"
android:layout_width="265dp"
android:layout_height="40dp"
android:maxLength="10"
android:textSize="18dp"
android:inputType="date"
android:hint="Date of Birth"
android:background="@drawable/edittext_yellow_singleline" />
<ImageButton
android:id="@+id/img_dob"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cal" />
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="10dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/country"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="textPostalAddress"
android:layout_marginRight="20dp"
android:hint="Country"
android:background="@drawable/edittext_yellow_singleline" />
<EditText
android:id="@+id/zipcode"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:maxLength="6"
android:textSize="18dp"
android:layout_weight="1"
android:inputType="number"
android:layout_marginRight="20dp"
android:hint="Zipcode "
android:background="@drawable/edittext_yellow_singleline" />
<Spinner
android:id="@+id/gender"
android:layout_width="305dp"//finally hard coded but it wont work for multiple screens
android:layout_height="40dp"
/>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="30dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/ok"
android:layout_width="100dp"
android:layout_height="40dp"
android:gravity="center"
android:textSize="20dp"
android:text="Done"
android:background="@drawable/login_button_shape" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
如果不行,table布局会给出解决方案吗?
如果我减少提示中的文本,那么它在第二行也能正常工作。如果我提供 space 以与包含低文本的其他 edittext 字段保持相同的文本长度也不起作用。
你所有的 EditText 应该有:
android:layout_width="0dp"
所有的LinearLayout都应该有:
android:weightsum="3"