gpt4 book ai didi

布局 ScrollView 中的android textview ScrollView

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:43 24 4
gpt4 key购买 nike

我在我的 LinearLayout 中设置了 ScrollView。我想要一个 TextView 来滚动。我试过像这样在 xml 中使用 ScrollView。但是,它不起作用。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">

<!-- first scrollView -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_corner_blue"
android:gravity="center"
android:text="@string/personalInformation"
android:textColor="@android:color/white" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/birthDate" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" TestData" />

</LinearLayout>

<!-- second scrollView -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textOphthalmoscopy"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="standard instrth various settings that allow focusing and adjustment of the light source to accommodate the viewer and to evaluate various features of the fundus." />
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>

我试过这样的另一种方式,但还是不行。

android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"

我用过

myTextView.setMovementMethod(new ScrollingMovementMethod());

那么如何让TextView滚动呢?如果是第二个ScrollView

最佳答案

您可以考虑使用 NestedScrollViewListView 来显示可滚动的 TextView

ListView 将有一个固定的大小,这样它就不会占据里面项目的总高度。

所以布局可能是这样的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">

<!-- first scrollView -->
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_corner_blue"
android:gravity="center"
android:text="@string/personalInformation"
android:textColor="@android:color/white" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/birthDate" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" TestData" />
</LinearLayout>

<ListView
android:layout_width="match_parent"
<!--set a fixed height-->
android:layout_height="80dp"
.. Other attributes
</ListView>
</LinearLayout>
</NestedScrollView>
</LinearLayout>

并且 ListView 的列表项可能包含您要滚动的 TextView。将 TextView 的高度设置为 wrap_content

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">

<TextView
android:id="@+id/textOphthalmoscopy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="standard instrth various settings that allow focusing and adjustment of the light source to accommodate the viewer and to evaluate various features of the fundus." />
</LinearLayout>

现在您的 ListView 将有一个项目,这将以列表的默认行为滚动。

整个布局将通过 NestedScrollView 滚动。

希望对您有所帮助!

关于布局 ScrollView 中的android textview ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41800731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com