2012-04-17 62 views
0

我只是像这样添加滚动视图,并在屏幕加载后出现黑色背景。滚动视图导致黑色背景出现

这个黑色区域位于周围的RelativeLayout的左上角。虽然滚动视图与android:layout_marginLeft="20dp" android:layout_marginTop="40dp"定位所以左20dp和顶部40dp是黑色,而其余的灰色背景是不受干扰的。

这里的XML部分与滚动视图:

<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个RelativeLayouts添加emptyView。但是不管怎样,黑色区域一直在出现。 (有/没有RelativeLayouts和顶部的空视图)

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

我以前使用过多次滚动视图,但从来没有像这样的问题。我不知道是什么导致了这一点。

如何摆脱由滚动视图引起的黑色区域?

非常感谢!

回答

2

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

 //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); 
+0

如果您可以提供代码示例,那就太好了。 – giZm0 2012-07-06 10:14:11

+0

我不知道代码示例应该如何帮助你。在我的情况下,解决方案是添加一个scrollView填充布局,并将您想要的布局背景颜色设置为不是scrollView。上面的代码没有经过测试,但也许会有所帮助。 – 2012-07-06 14:18:44