tags:

views:

22

answers:

1

Hello

I have a TextView in a ScrollView with a specific background image. My problem is that if the text is longer than one line, the TextView will stretch as much as the screen allows it. I would like the text view's sizes to remain the same (the sizes of the background)

<ScrollView android:id="@+id/description"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/padding_large"
    >
    <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="@dimen/padding"
        android:paddingBottom="@dimen/padding"
        android:paddingLeft="@dimen/padding_large"
        android:paddingRight="@dimen/padding_large"
        android:background="@drawable/textfield_background_small"
        android:inputType="textMultiLine"
        android:text="@string/step_description"
      />
 </ScrollView>

Thanks a lot

A: 

Using wrap_content makes a layout dynamic, i.e. its size will grow and shrink depending on its content. If you instead change all your wrap_content to fill_parent the layouts will fill their parent container entirely.

You can read more about how to properly declare layouts here: http://developer.android.com/guide/topics/ui/declaring-layout.html

Nailuj
If I set wrap_fill_parent for the ScrollView, it will extend on the whole screen. If I set fill_parent for the TextView, and wrap_content for the ScrollView it's the same scenario as in the first time when both of them had wrap_content. All I want is, the TextView to have the background image sizes, when the text reaches the right edge a new line to be inserted and when the text reaches the bottom edge the scroll to be enabled.
Gratzi
Ok, think I misunderstood your question a bit at first. I don't think that is possible, at least not by only using the XML layout (the dynamic layout size is based on the `View`'s _content_, and the background doesn't count there (I think)). You could try (but this is only a wild guess, I haven't tested it) to override the `measure(int, int)` of your `View` in code (http://developer.android.com/reference/android/view/View.html#measure%28int,%20int%29), but this would lead to the size of your view using explicit sizes - which generally is a bad thing, as you should strive to use relative sizes.
Nailuj
I know it's bad to use explicit sizes, but I want a TextView with a certain background, and I would prefer to display the original image with the original sizes. If it's stretched, the image doesn't look so good, and I can't use 9 patch either, because of its content. That was the aesthetic problem. The layout problem is that I have an ImageView at the right of the text view that isn't displayed, because the TV occupies the whole screen's width. Maybe creating a custom ScrollView is the best solution for this... Thanks a lot!
Gratzi