Android 开发中ScrollView无法上下滚动

2023-11-11

本节目录

问题

  因项目需要做一个App出来,所以最近在学Android Studio开发,但是我在利用ScrollView实现内容上下滚动的时候出现了一个问题,就是无法将超出页面的内容进行上下滑动,设计UI界面如下:
在这里插入图片描述
这里的TextView的高度是我直接用鼠标拉出来的,但是程序运行的结果却无法进行滑动,只能显示部分内容而且我设计右边的滑块也没有显示出来,同时“滚动底部” button 按钮的功能也无法实现,如下:

解决办法:

  Scroll的子元素只能有一个,其子元素内部则不受限制,但是我们在添加控件的时候要注意子元素的高度,否则运行出来的结果无法达到预期的效果,后面我将TextView的layout_height属性改为了wrap_content之后,便成功了!!!

最后附上部分UI代码:

<ScrollView
        android:id="@+id/scrolview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="true"
        android:scrollbarSize="3dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbarThumbVertical="@android:drawable/btn_default"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:layout_editor_absoluteX="0dp">

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

            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/button1" />

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/textview" />
        </LinearLayout>
    </ScrollView>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 开发中ScrollView无法上下滚动 的相关文章

随机推荐