Reputation: 25
I have 2 TextViews, and I want to assign 67% of the space to title
and the remaining 33% to the details
.
<LinearLayout
android:id="@+id/layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginStart="4dp"
android:layout_marginEnd="@4dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16sp" />
<TextView
android:id="@+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp" />
</LinearLayout>
Upvotes: 1
Views: 502
Reputation: 1052
Set the widths of the TextView
s as 0dp
and set layout_weight
as 2 for title TextView
and layout_weight
as 1 for description TextView
.
Upvotes: 0
Reputation: 12138
Use weight sum
on LinearLayout
as 4 & provide weight to both TextView
like below:
<LinearLayout
android:id="@+id/layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4"
android:layout_marginStart="4dp"
android:layout_marginEnd="@4dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textSize="16sp" />
<TextView
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:layout_weight="3"
android:maxLines="1"
android:textSize="16sp" />
Upvotes: 1