亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何讓我的視圖在 Android 上可滾動?

如何讓我的視圖在 Android 上可滾動?

明月笑刀無情 2023-07-28 16:27:08
我創建了 xml 視圖,在預覽中看起來效果不錯。但是當我在模擬器上玩時,元素無法修復,我認為模擬器太小了。所以我嘗試過的解決方案是將滾動條設置為垂直:<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"?/>但它沒有生效,我認為它只適用于列表或長文本?
查看完整描述

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>


查看完整回答
反對 回復 2023-07-28
?
米脂

TA貢獻1836條經驗 獲得超3個贊

嘗試在您的 xml 中添加 android:

layout_marginBottom="16dp"

這樣 TextView 應該距底部至少 16dp 或將其包裹在里面


查看完整回答
反對 回復 2023-07-28
?
慕森王

TA貢獻1777條經驗 獲得超3個贊

我認為問題在于默認情況下,TextView 只是一個單行對象。如果你想顯示多行,你需要在 xml 布局中定義它們:

android:maxLines="10"
android:lines="5"


查看完整回答
反對 回復 2023-07-28
?
慕森卡

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高度/寬度。


查看完整回答
反對 回復 2023-07-28
?
蕭十郎

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


查看完整回答
反對 回復 2023-07-28
  • 5 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號