gpt4 book ai didi

android - ScrollView 内的滚动文本不起作用

转载 作者:太空狗 更新时间:2023-10-29 13:46:49 24 4
gpt4 key购买 nike

我有一个 ScrollView,里面有一些字段,中间有一个包含冗长文本的 TextView

所以我想要可滚动的 TextView,用户可以通过它滚动整个表单以及 TextView 中的文本,具体取决于他选择滚动的区域。

我的布局是这样的

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".BtcActivity">


<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

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

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="hi" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />


<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rel_layout"
android:layout_margin="16dp"
android:layout_marginTop="15dp"
android:elevation="1dp"
android:maxLines="5"
android:paddingBottom="10dip"
android:scrollbars="vertical"
android:text="@string/dummy" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

我想要这样的东西

我还尝试了 this 的解决方案& this它们都不适用于我的情况。

最佳答案

布局:

<?xml version="1.0" encoding="utf-8"?>
<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.support.v4.widget.NestedScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

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

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="hi" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />


<ScrollView
android:fillViewport="true"
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="60dp">

<TextView
android:id="@+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rel_layout"
android:elevation="1dp"
android:text="hi\n1\n2\n3\n4\n5\n6\n7\n8"
android:paddingBottom="10dip"
android:scrollbars="vertical"/>

</ScrollView>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>

Java 文件修改

ScrollView scrollView = findViewById(R.id.sv);
scrollView.setNestedScrollingEnabled(true);

关于android - ScrollView 内的滚动文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52216900/

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