0

我正在构建一个教程应用程序,我在其中向用户显示代码片段,但滚动只是在屏幕的白色区域上工作,而不是在代码片段上,可能是代码视图与滚动视图重叠,如何解决它以便代码视图也滚动:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="activity_main.xml"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            android:layout_marginTop="5dp"
            android:textSize="18sp"/>

        <io.github.kbiakov.codeview.CodeView
            android:id="@+id/code_view_xml"
            android:layout_marginTop="7dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="create layout resource file inside layout directory with name:"
            android:layout_marginTop="10dp"
            android:textColor="#000000"
            android:textStyle="italic"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="single_item.xml"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            android:layout_marginTop="5dp"
            android:textSize="18sp"/>

        <io.github.kbiakov.codeview.CodeView
            android:id="@+id/code_view_item"
            android:layout_marginTop="7dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>


    </LinearLayout>

</ScrollView>

这里的输出:

截屏

4

1 回答 1

0

您缺少填充。尝试添加填充。此外,您的线性布局高度是 match_parent。将其更改为换行,然后尝试

于 2021-11-08T05:59:39.607 回答