开发者

Android Scroll View Background Color

开发者 https://www.devze.com 2023-02-17 23:18 出处:网络
Is there a way to set the background color for the scrollview element? I\'ve tried the following code below but the colors aren\'t being applied:

Is there a way to set the background color for the scrollview element? I've tried the following code below but the colors aren't being applied:

<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">#00000开发者_运维知识库0</color>
    <color name="colorLightBlue">#33A1C9</color>
</resources>


Try this `

<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>

`


I'm not sure if this is the proper way to do this, but I wrapped the Scroll in another LinearLayout and set the background to white and it worked.


I had the same issue, I realised it was because the ScrollView was in my fragment layout and my activity layout had the fragment element set as layout_height="wrap_content". So no matter what I put in the fragment it still didn't occupy the whole screen until I changed it to layout_height="match_parent" in the activity layout.

0

精彩评论

暂无评论...
验证码 换一张
取 消