質問

I have an oddly organized activity with a number of LinLayouts inside of LinLayouts inside of LinLayouts (inside of LinLayouts) all so that each little section is organized correctly. Everything looks good except for one part.

I have a vertical LinearLayout with two things inside of it. One is another LinearLayout with weight set to 6, and below it is a TextView weight set to 1. What I want to do is have the height of the TextView to scale depending on the amount of lines in it. It could either be a one-liner sentence or maybe a four-line paragraph--I don't know what it'll end up. Then the LinLayout above it needs to fill in the rest of the height.

What layout_height settings do I need to combine to get this to work?

役に立ちましたか?

解決

Finally figured it out. It's sort of weird, but this is what I had to do:

<LinearLayout
    android:id="@+id/everything_but_description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal" />

<TextView
    android:id="@+id/description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/paragraph" />

I had to have both set to "wrap_content" but give the one I wanted to fill the remaining space a weight WITHOUT giving the other one a weight. Very weird workaround but it works perfectly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top