I have a linearlayout with 2 image views and a text view. I want proper space distribution within the layout row. It should be somethink like below
______________________________
|IV| |IV|
| | <-- Text View -----> | |
_______________________________
How can I achieve this? I want all the space assigned to textview after fitting the two images.
Below is my attempt and its not working.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_below="@+id/addTrip"
android:layout_weight="1" android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="left"
android:src="@drawable/icon" />
<TextView android:layout_weight="1" android:id="@+id/textView1"
android:clickable="true" android:layout_width="0dp"
android:layout_height="wrap_content" android:gravity="right"
android:text="Enter trip name"></TextView>
<ImageView android:id="@+id/imageView1"
android:layout_gravity="right" android:src="@drawable/edit"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
I am using this as Layout inflater.
ArrayList<TripInfo> trips = inst.getListOfTrips(); //reading from DB
for (int i =0; i < trips.size(); i++) {
TripInfo tobj = trips.get(i);
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout lrow = (LinearLayout)vi.inflate(R.layout.triprow, null);
((TextView)lrow.getChildAt(1)).setText(tobj.getName());
placeHolderLinearLayout.addView(lrow);
}
Experts please provide some input. Do I have to set anything in the code as well.
Both image views should have:
android:layout_width="wrap_content"and noandroid:layout_weightspecified.And the central
TextViewshould haveandroid:layout_width="0dp"andandroid:layout_weight="1".In fact it doesn’t matter if you have
1or any other value specified as weigght. As long as this is the only view that haslayout_weightit takes up all free space. So you can easily fix you example just by removingandroid:layout_weight="0.2"in lastImageView.