-1

When I use ScrollView, no matter how I set it up, Scrollview will always have a green border, setting the background to Scorllview doesn’t work.

enter image description here

Below is part of my xml file

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ScrollView
            android:id="@+id/left_sv"
            android:layout_width="@dimen/px_180"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            android:background="@null"
            android:scrollbars="none"
            android:fadingEdge="none" >

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

                <RelativeLayout
                    android:id="@+id/rl_setting_quota"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/px_50"
                    android:gravity="center_vertical">

                    <ImageView
                        android:layout_width="@dimen/px_30"
                        android:layout_height="@dimen/px_30"
                        android:layout_marginLeft="@dimen/px_10"
                        android:src="@drawable/icon_szxianling" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="@dimen/px_30"
                        android:layout_marginLeft="@dimen/px_40"
                        android:gravity="center"
                        android:text="@string/str_setting_quota"
                        android:textSize="@dimen/px_16" />

                    <ImageView
                        android:id="@+id/iv_arr_setting_quota"
                        android:layout_width="@dimen/px_15"
                        android:layout_height="@dimen/px_15"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="@dimen/px_10"
                        android:src="@drawable/arrow_right" />
                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/px_1"
                    android:background="@drawable/line_shape" />

                <RelativeLayout
                    android:id="@+id/rl_setting_time"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/px_50"
                    android:gravity="center_vertical">

                    <ImageView
                        android:layout_width="@dimen/px_30"
                        android:layout_height="@dimen/px_30"
                        android:layout_marginLeft="@dimen/px_10"
                        android:src="@drawable/icon_shijian" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="@dimen/px_30"
                        android:layout_marginLeft="@dimen/px_40"
                        android:gravity="center"
                        android:text="@string/str_setting_time"
                        android:textSize="@dimen/px_16" />

                    <ImageView
                        android:id="@+id/iv_arr_setting_time"
                        android:layout_width="@dimen/px_15"
                        android:layout_height="@dimen/px_15"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="@dimen/px_10"
                        android:src="@drawable/arrow_right" />
                </RelativeLayout>

            

                <View
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/px_1"
                    android:layout_marginBottom="@dimen/px_30"
                    android:background="@drawable/line_shape" />
            </LinearLayout>
        </ScrollView>

        

        </LinearLayout>
    </LinearLayout>

</LinearLayout>
The LinearLayout label is my root layout, there is a ScrollView layout inside, a LinearLayout layout is placed in the ScrollView, and then there are multiple RelativeLayout layouts in the LinearLayout layout

4

1 回答 1

0

我已经发现了这个问题的原因。出现这个问题是因为焦点问题,而不是Scrollview本身的问题,因为一进入界面焦点就转移到了Scrollview上。只需要在ScrollView的父布局中设置以下两个参数即可。可以解决问题:android:focusable="true" android:focusableInTouchMode="true"

于 2020-08-07T09:27:47.987 回答