Reputation: 1567
I have 5 horizontal linear layout is there. I aligned three edittext in a single linear layout. And I applied the weight field property 1 for all the editext. But in 1st and 3rd linear layout working perfectly with the property. Others are not working properly. Again in 5th horizontal linear layout have one spinner view, it was also creating the same problem. Then 4th line one addition linear layout available inside the horizontal layout, with one edittext and one imageview. It is also not fixing properly with weight property. I put layout code below.
<?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>
If it won't work means, will the table layout give solution for this?
If I reduce the text inside the hint then also it was working fine in 2nd line. If I provide space for keeping same text length in with other edittext field which contains low text also not worked.
Upvotes: 0
Views: 344
Reputation: 3773
All your EditText should have:
android:layout_width="0dp"
And all LinearLayout should have:
android:weightsum="3"
Upvotes: 2