Reputation: 1
How can I set the LinearLayout
items' heights to be the same? I tried with RelativeLayout
but didn't have any success. Any idea how I can do it?
<LinearLayout
android:background="@color/red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:weightSum="11">
<TextView
android:id="@+id/lblParca"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="5.5"
android:text="Parça Kodu"
android:textSize="15dp" />
<EditText
android:id="@+id/txthldMalzemeKodu"
style="@style/DefaultEditTextSmall"
android:layout_width="0dip"
android:layout_weight="4.5"
android:layout_height="wrap_content"
android:inputType="textCapCharacters"
android:singleLine="true" />
<ImageButton
android:id="@+id/btnhldgetMalzeme"
style="@style/btnStyleBreakerBay"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_ara" />
</LinearLayout>
That's what I got:
Upvotes: 0
Views: 2255
Reputation: 3389
If you are happy with Aspicas answer, the layout can be simplified to just
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@color/red"
android:orientation="horizontal">
<TextView
android:id="@+id/lblParca"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0.40"
android:text="Parça Kodu" />
<EditText
android:id="@+id/txthldMalzemeKodu"
style="@style/DefaultEditTextSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:inputType="textCapCharacters"
android:singleLine="true"/>
<ImageButton
android:id="@+id/btnhldgetMalzeme"
style="@style/btnStyleBreakerBay"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.20"
android:scaleType="centerInside"
android:src="@mipmap/ic_ara"/>
</LinearLayout>
There is no need to have all of the wrappers. Also notice the change to your TextView utilizing gravity
instead of layout_gravity
to center your content. I am actually surprised this works, from my understanding this should be stretching the height of the views, apparently I was wrong in that thinking.
Upvotes: 0
Reputation: 3964
One way is to hardcode the Parent's LinearLayout Height .
Other way is to take 3 Linear Layout for each of the items & in each LinearLayout
set
android:layout_gravity="center_vertical"
Upvotes: 0
Reputation: 4497
Try with this xml file
<?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="wrap_content"
android:layout_marginTop="5dp"
android:background="@color/red"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0.40"
android:orientation="horizontal">
<TextView
android:id="@+id/lblParca"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Parça Kodu"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:orientation="horizontal">
<EditText
android:id="@+id/txthldMalzemeKodu"
style="@style/DefaultEditTextSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textCapCharacters"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.20"
android:orientation="horizontal">
<ImageButton
android:id="@+id/btnhldgetMalzeme"
style="@style/btnStyleBreakerBay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_ara"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 5839
You can try to use android:layout_weight="1"
for all views, and set android:layout_height="0"
Link on documentation.
Upvotes: 1
Reputation: 1229
you need to set up the same height for all the views. Either you do this:
android:layout_height="match_parent"
or
android:layout_height="some value"
Upvotes: 0