它应该这样WRAP_CONTENT
做:
视图请求的高度或宽度的特殊值。
WRAP_CONTENT
意味着视图希望足够大以适合其自己的内部内容,同时考虑到自己的填充。
但现实不同
如果您创建一个非常长的文本视图,其高度大于屏幕高度,则WRAP_CONTENT
应用于该文本视图的高度会产生错误行为,因为将文本视图高度限制为屏幕高度。
android:layout_height="wrap_content"
为什么WRAP_CONTENT
会有这种错误行为?
如何设置视图以使其内容的大小不受屏幕高度的限制?
完整的 XML 文件(这是游戏结束标题的屏幕,文本将被动画化,因为它隐藏在屏幕下方):
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/creditsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/credits_big"
android:textAlignment="center"
android:textColor="@color/font"
android:textSize="@dimen/medium_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>