簡體   English   中英

如何在Android中使用相對布局向滾動視圖添加背景圖像?

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

嗨,我已經創建了一個帶有按鈕的scrollview應用程序,我添加了一個背景圖像,但是背景可以在模擬器上運行,但不能在真實設備上運行,任何幫助將不勝感激,即時通訊使用imageview作為背景!

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

我可以向下滾動它的長圖像,並且效果很好,但是在實際設備上,滾動功能正常,按鈕在正確的位置,只是背景不顯示?

您應該將背景圖像設置為@drawable XML資源。 這樣,您可以使用android:background="@drawable/..."將其設置為背景,以使其成為背景(無論是ScrollView還是RelativeLayout)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM