如何在 android 中将背景图像添加到具有相对布局的滚动视图?
how to add a background image to a scrollview with relative layout in android?
你好,我创建了一个带按钮的滚动视图应用程序,我添加了一个背景图像,但背景在模拟器上有效,但在真实设备上无效,我们将不胜感激,我使用图像视图作为背景!
<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)的背景。
你好,我创建了一个带按钮的滚动视图应用程序,我添加了一个背景图像,但背景在模拟器上有效,但在真实设备上无效,我们将不胜感激,我使用图像视图作为背景!
<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)的背景。