Android 如何根据文本长度设置高度布局?
我有Scrolview、布局和文本视图Android 如何根据文本长度设置高度布局?,android,android-layout,height,Android,Android Layout,Height,我有Scrolview、布局和文本视图 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <L
<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句)时,版面高度应大于屏幕高度,且取决于文本的长度 将
android:layout\u height=“wrap\u content”
放在你的布局中,这样应该可以相应地调整布局。将android:fillViewport=“true”
添加到滚动视图中,并设置子项android:layou height=“wrap\u content”
。(引自)
<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>