2013-11-24 2 views
0

У меня есть Scrolview, Layout и TextView.Как настроить длину текста в зависимости от длины текста?

<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/Layout" 
       android:orientation="vertical" 
       android:background="@null" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
    <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Text" 
      android:layout_gravity="left|center_vertical"/> 
    </LinearLayout> 
    </ScrollView> 

Как установить высоту макета зависит длина текста ?? Если текст короток, высота макета должна быть равна высоте экрана. Но когда текст длинный (например, более 100 предложений) высота макета должна быть больше высоты экрана и зависит от длины текста.

ответ

0

Поместите android:layout_height="wrap_content" в ваш макет, и это должно масштабировать его соответствующим образом.

0

Добавить android:fillViewport="true" в команду ScrollView, а также установить детей android:layout_height="wrap_content". (Рефералы от ScrollView's handy trick)

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/Layout" 
      android:orientation="vertical" 
      android:background="@null" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:layout_gravity="left|center_vertical"/> 
    </LinearLayout> 
</ScrollView> 
Смежные вопросы