我希望创建具有线性布局的滚动视图,其中将包含文本视图(在 Android Studio 中)。但我的滚动视图不起作用。而且我也无法添加超过 AVD 屏幕尺寸的文本。我的 XML 代码如下:-
`<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="723dp"
android:padding="25dp"
android:text="@string/textview"
android:textSize="24sp" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>`
I expect my Android app to have scrollview with linearlayout and with Textview showing lengthy text which can be scrolled vertically
使用此代码
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Rahul"
android:gravity="center"
android:textSize="20sp"/>
</LinearLayout>
</ScrollView>