【问题标题】:how to fix the scrolling width of HorizontalScrollView?如何修复 Horizo​​ntalScrollView 的滚动宽度?
【发布时间】:2021-12-27 13:12:05
【问题描述】:

Hlo 查看器,我正在构建一个使用 codeview 的应用程序,因此为了查看所有 codeview,我为 codeview 放置了一个水平滚动视图,它工作正常,但水平滚动视图一直在滚动,它会影响优化,但是我可以修复 Horizo​​ntalScrollView 的宽度,以便代码只能滚动到结尾。谢谢

这里是代码:

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

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <br.tiagohm.codeview.CodeView
            android:id="@+id/code_view"
            android:layout_width="700dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:scrollbars="horizontal"
            app:cv_font_size="12"
            app:cv_show_line_number="true"
            app:cv_start_line_number="1"
            app:cv_wrap_line="true"
            app:cv_zoom_enable="true">

        </br.tiagohm.codeview.CodeView>
    </HorizontalScrollView>


</ScrollView>

【问题讨论】:

    标签: java android horizontalscrollview code-view


    【解决方案1】:

    我找到了解决方案,对于片段中 horizintalscrollview 的自定义宽度,我们必须这样做:

    <?xml version="1.0" encoding="utf-8"?>
    <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <br.tiagohm.codeview.CodeView
                android:id="@+id/code_view"
                android:layout_width="1000dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="7dp"
                app:cv_font_size="12"
                app:cv_show_line_number="true"
                app:cv_start_line_number="1"
                app:cv_wrap_line="true"
                app:cv_zoom_enable="true">
    
            </br.tiagohm.codeview.CodeView>
        </LinearLayout>
    
    </HorizontalScrollView>

    【讨论】: