【问题标题】:How to use scrollview over codeview?如何在代码视图上使用滚动视图?
【发布时间】:2021-12-21 00:35:51
【问题描述】:

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

<?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>

这里是输出:

【问题讨论】:

标签: java android scrollview code-view


【解决方案1】:

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

【讨论】:

  • 我需要在哪里添加填充?
猜你喜欢
  • 1970-01-01
  • 2010-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 1970-01-01
相关资源
最近更新 更多