2011-03-18 82 views
0

有没有办法设置scrollview元素的背景颜色?我试过下面的下面的代码,但都没有被应用颜色:Android滚动查看背景颜色

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:scrollbars="vertical" android:background="@color/colorWhite"> 
<?xml version="1.0" encoding="utf-8"?> 

<resources> 
    <string name="app_name">Trackfolio</string> 
    <color name="colorWhite">#FFFFFF</color> 
    <color name="colorBlack">#000000</color> 
    <color name="colorLightBlue">#33A1C9</color> 
</resources> 
+0

这就是全部在一个文件?布局和资源类型应该位于不同的文件中。所以你需要res/layout/scrollview.xml,res/values/resources.xml。但如果它们在单独的文件中,那么你的语法看起来是正确的ScrollView内的内容是否正确显示? – 2011-03-18 21:50:59

+1

是的,他们在不同的文件。这些是代码剪辑 – locoboy 2011-03-18 21:59:48

+0

你在Scrollview中嵌套了什么样的元素? – Jorgesys 2011-03-18 22:50:55

回答

4

试试这个`

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ScrollView 
     android:layout_width="100dip" 
     android:layout_height="120dip" 
     android:background="#FF0000"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 


      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/scrollbar_2_text" /> 
     </LinearLayout> 
    </ScrollView> 

    <ScrollView 
     android:layout_width="100dip" 
     android:layout_height="120dip" 
     android:background="#00FF00" 
     android:paddingRight="12dip"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/scrollbar_3_text" 
      android:textColor="#000000" 
      android:background="#60AA60" /> 
    </ScrollView> 

    <ScrollView 
     android:id="@+id/view3" 
     android:layout_width="100dip" 
     android:layout_height="120dip" 
     android:background="@android:drawable/edit_text"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:text="@string/scrollbar_3_text" /> 
    </ScrollView> 
</LinearLayout> 

`

0

我不知道这是否是这样做的正确方法,但我裹滚动在另外的LinearLayout和设置背景白色和它的工作。