2

Is it possible to tell a view, that it should at least wrap it's content but if the parent view leaves space to stretch, than it should fill it's parent?

Example:

What I want is, that the container linear layout wraps around it's content... and that in case of that my title text view is wider than the scroll view, it does NOT get cut! If I set the title textview to wrap_content, it does not fill it's parent if the scrollview is wider than the title...

 <LinearLayout
                android:id="@+id/llWeightsParent"
                style="@style/group"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:clickable="true"
                android:onClick="onClick"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tvWeight"
                    style="@style/text_group_title"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:text="@string/weight" />

                <ScrollView
                    android:id="@+id/svWeights"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent" >

                    <LinearLayout
                        android:id="@+id/llWeights"
                        style="@style/group_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical" >
                    </LinearLayout>
                </ScrollView>
            </LinearLayout>
prom85
  • 16,896
  • 17
  • 122
  • 242
  • some of code can explain us more about your problem. – Bhavesh Patadiya Jun 13 '13 at 07:54
  • surround the text view with a `LinearLayout` or a `RelativeLayout`, the surrounding layout will have match_parent and the `TextView` wrap_content, so it will fill the parent and will also have wrap_content – bogdan Jun 13 '13 at 08:29
  • I just tried that... But that's not working either... still the same behaviour as my example... – prom85 Jun 13 '13 at 08:37

1 Answers1

0

If what you mean is imageview, then you can set

android:layout_width="match_parent"
android:scaleType="centerInside"

For others I'd just set android:layout_width="match_parent" and won't worry too much about it.

Neoh
  • 15,906
  • 14
  • 66
  • 78
  • Can you elaborate on why set layout_width to `match_parent` isn't enough for you? – Neoh Jun 13 '13 at 08:15
  • just added an example and a more detailed explanation... it's the two parts complexity that is the problem... – prom85 Jun 13 '13 at 08:16
  • One suggestion: try set all your child views to layout_width="match_parent" and set the outermost parent linearlayout to layout_width="wrap_content". – Neoh Jun 13 '13 at 08:26
  • I think that's not working at all... In my case I'm sure it does not, tried that already... I use more than one of the layouts above next to each other and fill the rest with another view... – prom85 Jun 13 '13 at 08:33