5 回答

TA貢獻1906條經驗 獲得超10個贊
您需要使用 ScrollView 作為父布局,如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

TA貢獻1836條經驗 獲得超3個贊
嘗試在您的 xml 中添加 android:
layout_marginBottom="16dp"
這樣 TextView 應該距底部至少 16dp 或將其包裹在里面

TA貢獻1777條經驗 獲得超3個贊
我認為問題在于默認情況下,TextView 只是一個單行對象。如果你想顯示多行,你需要在 xml 布局中定義它們:
android:maxLines="10" android:lines="5"

TA貢獻1806條經驗 獲得超8個贊
只需將當前代碼包裝到 Scrollview 中,如果文本太大或溢出,它就會滾動。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollview"
>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ScrollView>
請注意,我正在使用match_parent這意味著它將占用所有可用空間,因此請仔細檢查您是否不需要類似的wrap_content高度/寬度。

TA貢獻1815條經驗 獲得超13個贊
為此,您需要將 TextView 放入 ScrollView 中。但是,請注意,ScrollView 內部只能有一個直接子級(https://developer.android.com/reference/android/widget/ScrollView.html)。如果您需要將多個視圖放入滾動視圖中,您可以將它們放入 LinearLayout 中,然后將此 LinearLayout 放入 ScrollView 中,就像 Jagar 指出的https://stackoverflow.com/a/57928644/12019759
添加回答
舉報