Ksice
Ksice

Reputation: 3327

How to fill layout with content with different weights like a percentage widths?

I have horizontal layout with total weight 10. I want to put some content with different width on it. I want my content on it looks like next proportion of it's widths: 3:5:1:1 i.e. like a table with columns 30%, 50%, 10%, 10% How to organize this? Now I have:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:baselineAligned="true"
    android:clipChildren="false"
    android:orientation="horizontal"
    android:useLargestChild="true"
    android:weightSum="10" >

And TextViews with different weights like this:

<TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:layout_weight="3"
        android:padding="2dp"
        android:text="TextView 1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

But it didn't work. Views are located out of screen. If I change match_parent to wrap_content it looks OK while I don't place large text on it, then TextView grows up. I don't want it, I want to show only that part of text, that will be wrap in current 30, or 50, or etc %.

Upvotes: 0

Views: 359

Answers (2)

Ksice
Ksice

Reputation: 3327

I've found the solution in limit text in container using

android:maxEms="<Wieght of this TextView>"

Seems to work ok. But I'm not sure is it correct or not.

Upvotes: 0

Changwei Yao
Changwei Yao

Reputation: 13101

You set the android:layout_width="match_parent" to android:layout_width="0dp"

Upvotes: 2

Related Questions