我真的感觉很恶心
文本视图的高度不会改变
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Hello"
android:textSize="40sp"
android:gravity="center"
/>
</ScrollView>
答案 0 :(得分:1)
将视图的大小设置为wrap_content将强制它仅扩展到足以包含它包含的值(或子控件)。由于您的孩子身高不一,父元素也是如此。
答案 1 :(得分:1)
好的 - 所以你已经将你的滚动视图设置为:
android:layout_height="wrap_content"
这实际上没有意义,因为您可以滚动视图以查看更多项目。这就是scrollview的目的。通常,scrollviews通常是match_parent。将xml更改为下面的滚动值,它应该可以工作。
android:layout_height="match_parent"
答案 2 :(得分:1)
在ScrollView中保留LinearLayout。
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linear">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Hello"
android:textSize="40sp"
android:gravity="center"
/>
</LinearLayout>
您还可以将LinearLayout的高度更改为100dp,因此默认情况下是否为LinearLayout / TextView保留100dp空间(TextView中是否有任何文本)
PS:在scrollView中使用LinearLayout是一个好习惯。控制并保持子对象对齐将更容易。
我希望它有效。欢呼声。
答案 3 :(得分:1)
我认为这与你正在使用的布局有关。我使用了以下LinearLayout和textview的大小更改。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Hello"
android:textSize="80sp"
android:gravity="center"
/>
</ScrollView>
<LinearLayout>