简体   繁体   中英

how to add a background image to a scrollview with relative layout in android?

hi i have created a scrollview application with button, i have added a background image but the background works on the emulator but not on a real device, any help will be appreciated, im using an imageview as a background!

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 >
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:isScrollContainer="true"
    android:orientation="vertical"
    >

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="3500dp"
    android:adjustViewBounds="true"
    android:background="@drawable/iphonebg"
    android:clickable="false"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"

    android:contentDescription="@string/background_desc"
    >
</ImageView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/callButton"
        android:background="@drawable/callnow1"
        android:layout_marginTop="261dp"
        android:onClick="callButtonClicked"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/orderButton"
        android:layout_alignEnd="@+id/orderButton" />

i can scroll down its a long image and it works perfectly but on a real device the scroll is working and the buttons are in the right place just the background doesnt show?

You should set the background image as a @drawable XML resource. That way, you can set it as the background using android:background="@drawable/..." for whatever layout you want it to be the background of (either the ScrollView or the RelativeLayout).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM