Reputation:
I have one edittext and one textview in my linear layout and I gave same height to both, But still getting height difference.
here my xml. Please suggest me what am I doing wrong here ?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="10">
<TextView
android:id="@+id/lblKayitNo"
style="@style/NoviLabel"
android:layout_width="0dip"
android:layout_height="35dp"
android:layout_weight="4"
android:gravity="center_vertical|left"
android:text="Kayıt No" />
<EditText
android:id="@+id/txtKayitNo"
style="@style/DefaultEditTextSmall"
android:layout_width="0dip"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_weight="6"
android:enabled="false"
android:inputType="textCapCharacters"
android:singleLine="true" />
</LinearLayout>
Style Files
<style name="NoviLabel">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:fontFamily">sans-serif-small</item>
<item name="android:background">@drawable/novitextview_border</item>
</style>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
Upvotes: 0
Views: 393
Reputation: 29
use this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/lblKayitNo"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:text="Kayıt No" />
<EditText
android:id="@+id/txtKayitNo"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:inputType="textCapCharacters"
android:singleLine="true" />
</LinearLayout>
I think you use android:layout_weight="4"
for Textview and android:layout_weight="6"
foe EditText thats why this problem occure. so take same weight for both.
Upvotes: 1
Reputation: 500
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/lblKayitNo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center"
android:paddingTop="10dp"
android:gravity="center"
android:text="Kayıt No" />
<EditText
android:id="@+id/txtKayitNo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:enabled="false"
android:inputType="textCapCharacters"
android:singleLine="true" />
</LinearLayout>
Try this hope it may help
Upvotes: 0
Reputation: 4497
try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/lblKayitNo"
android:layout_width="0dp"
style="@style/NoviLabel"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|left"
android:text="Kayıt No"/>
<EditText
android:id="@+id/txtKayitNo"
android:layout_width="0dp"
style="@style/DefaultEditTextSmall"
android:layout_height="match_parent"
android:layout_weight="1"
android:enabled="false"
android:inputType="textCapCharacters"
android:singleLine="true"/>
</LinearLayout>
Upvotes: 1
Reputation: 1861
Do like this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="10">
<TextView
android:id="@+id/lblKayitNo"
style="@style/NoviLabel"
android:layout_width="0dip"
android:layout_height="35dp"
android:layout_weight="4"
android:gravity="center_vertical|left"
android:text="Kayıt No" />
<EditText
android:id="@+id/txtKayitNo"
android:layout_width="0dip"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_weight="6"
android:enabled="false"
style="@style/DefaultEditTextSmall"
android:inputType="textCapCharacters"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
You have to check the style attribute, by hiding style no problem in your code
Upvotes: 0
Reputation: 147
Try changing the android:layout_weight=
to be equal for both fields.
The layout_weight attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screenfrom the Android Developers Ref here: [link] http://developer.android.com/intl/es/guide/topics/ui/layout/linear.html
Upvotes: 0