2012-04-17 66 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