滚动视图导致黑色背景出现 [英] scrollview causes black background to appear

查看:56
本文介绍了滚动视图导致黑色背景出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是添加了一个像这样的滚动视图,在屏幕加载后会出现黑色背景.

I just add a scrollview like this and after the screen loads a black background appears.

这个黑色区域位于周围相对布局的左侧和最上角.当滚动视图使用 android:layout_marginLeft="20dp" 定位时android:layout_marginTop="40dp" 所以左边的20dp和上面的40dp是黑色的,而剩下的灰色背景不受干扰.

This black area is positioned on the left and upper most corner of a surrounding RelativeLayout. While the scroll view is positioned with android:layout_marginLeft="20dp" android:layout_marginTop="40dp" So the left 20dp and the top 40dp are black, while the remaining grey background is undisturbed.

这里是带有滚动视图的 xml 部分:

Here the xml part with the scrollView:

  <View
            android:id="@+id/emptyView"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_below="@+id/right1" />

        <RelativeLayout
            android:id="@+id/right2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/emptyView" >

            <RelativeLayout
                android:id="@+id/right22"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/emptyView" >

                <ImageView
                    android:id="@+id/emptyView2"
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:contentDescription="@string/anyStringValue" />

                <HorizontalScrollView
                    android:id="@+id/scrollView"
                    android:layout_width="fill_parent"
                    android:layout_height="520dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="40dp"
                    android:background="#0000FF" >

                    <TextView
                        android:id="@+id/infoTxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="#FF0000"
                        android:padding="10dp"
                        android:text="@string/Settings_infoTxt"
                        android:textColor="#000000"
                        android:textSize="20dp" />
                </HorizontalScrollView>
            </RelativeLayout>
        </RelativeLayout>

我已经尝试在滚动视图的顶部添加一个空视图以及 2 个相对布局.但无论如何,黑色区域一直出现.(有/没有相对布局和顶部的空视图)

I already tried to add an emptyView on top of the scroll view as well as 2 RelativeLayouts. But the black area keeps appearing no matter what. (with/without RelativeLayouts and empty views on top)

由于整个页面的背景是灰色的,这个黑色区域会扭曲整个屏幕.

Since the backgroud of the complete page is grey, this black area distorts the complete screen.

我以前多次使用滚动视图,但从未遇到过这样的问题.我不知道是什么导致了这种情况.

I used scroll views many times before but never had a problem like this. I have no idea what is causing this.

如何去除滚动视图导致的黑色区域?

非常感谢!

推荐答案

我遇到了几乎相同的问题,加载滚动视图时出现一些黑色区域,触摸时消失.我通过不设置滚动视图的背景颜色来解决它.设置内容视图的背景颜色应该就足够了.

I got pretty much the same problem, some black areas appeared on loading the scroll view, those disappeared on touch. I solved it by dont setting the background color of the scroll view. It should be enough to set the background color of the conten views.

      //outer layout, where black shapes appear
    LinearLayout outer = new LinearLayout(context);
    outer.setBackgroundColor(Color.MAGENTA);

    ScrollView list = new ScrollView(context);
    list.setLayoutParams(new LayoutParams(100, 300));

    //        do not set the background color here, this causes the blak shapes
    //        list.setBackgroundColor(Color.CYAN);
    //        add an inner layout to the scrollView and set the background of the innerlayout
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setBackgroundColor(Color.CYAN);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    list.addView(linearLayout);
    outer.addView(list);

这篇关于滚动视图导致黑色背景出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆