【发布时间】:2017-04-26 04:51:50
【问题描述】:
我有一个带有 3 个 TextView 的 Android ScrollView:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text1"
android:layout_weight="1"
android:text="short text 1"
android:textSize="30dp"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="0dp" />
<TextView
android:id="@+id/text2"
android:layout_weight="1"
android:text="Very long text Very long text Very long text Very long text"
android:textSize="50dp"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="0dp" />
<TextView
android:id="@+id/text3"
android:layout_weight="1"
android:text="short text 2"
android:textSize="30dp"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
</ScrollView>
我想要以下行为:
- 所有 TextView 的高度都相同 - 有效
- 如果文本没有填满屏幕,TextViews 应该填满整个屏幕(因此
fillViewport="true") - 有效 - 如果文本比屏幕大,ScrollView 开始滚动,而且 TextView 的高度仍然相等(所有 TextView 的高度等于 TextView 的最高值) - 不起作用:TextView 被剪裁,ScrollView 不滚动。
【问题讨论】:
-
当 textview2 的文本很长时,您希望 textviews 如何表现?
-
我希望 textViews2 的文本被完全看到,并且所有 textViews 应该具有相同的长度。所以 textView1 和 textView3 应该适应 textView2 的高度。由于整个布局会高于屏幕,我希望 ScrollView 滚动。
-
将
android:layout_height="wrap_content"放入滚动视图 -
那么 textView2 仍然被裁剪。它否定了 fillViewport="true" 的效果
-
@Damnum 这个问题的定义是错误的。因为如果你想要与
weight相同的高度,那么当第二个文本大小很大时,显然它会被剪裁。
标签: android android-layout textview android-scrollview