Android ScrollView question

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@color/colorPrimaryDark"
        android:text=""
        android:textSize="70sp" />

</ScrollView>

clipboard.png

Mar.04,2022

actual width and height of scrollview in code ~ = (approximately equal to) screen width and height, verification method, the height of scrollview that can be output in Activity is actually about equal to screen height, not content height

then it also has content width and height, which is determined by the size of the content.
android:layout_gravity= "center" aligns the center of the TextView to the center of the scrollview, but not the content center of the scrollview

if you want to align the content center, it is recommended to wrap a LinearLayout or other ViewGroup
around the TextView

code



        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/colorPrimaryDark"
            android:text=""
            android:textSize="70sp" />
    </LinearLayout>

</ScrollView>
Menu