1

我正在开发的应用程序有一个背景图像,我希望它可以缩放到不同的设备尺寸,最重要的是它应该适合宽度。背景逐渐变为黑色,所以我可以在主视图上拥有一个永久的黑色背景,看起来还不错。

我制作了一个 background.xml 文件,目前我在 res 文件夹中只有 800x1280 px 图形的 xlarge 背景图像。当我使用三星 Galaxy S3 的设置在 AVD 上运行我的应用程序时,背景宽度不会填满整个屏幕,但其余控件可以很好地缩放到屏幕上。

这是我观点的开始:

<ScrollView android:id="@+id/MainScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="#000000" 
    android:orientation="vertical"
    android:fillViewport="true">

<LinearLayout
    android:id="@+id/lineLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:background="@drawable/background"
    android:orientation="vertical"> 

我的 background.xml 看起来像这样:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
android:src="@drawable/mainappbg" 
android:gravity="top|left" android:filter="true" android:dither="true" />

希望有人可以提供帮助。

谢谢

我已经尝试过了,插入了一个图像作为背景,但只有 TasksButton 和 ServiceRapportButton 可见,其余内容消失。

<ScrollView android:id="@+id/MainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:background="#000000" 
android:orientation="vertical"
android:fillViewport="true">

<RelativeLayout 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent">
  <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/mainappbg"/>

<LinearLayout
android:id="@+id/lineLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
     android:layout_height="85dp">
   <Button android:id="@+id/TasksButton" android:layout_width="wrap_content"      android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:background="@drawable/opgaver" android:onClick="TasksClickHandler" android:textSize="12sp"/>
   <Button android:id="@+id/ServiceRapportButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="15dp" android:layout_marginTop="40dp" android:background="@drawable/rapport" android:onClick="ServiceRapportClickHandler" android:textSize="12sp"/>       
</RelativeLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tableLayout1">
      <Button android:id="@+id/LineButton" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="@drawable/lines" android:onClick="LineClickHandler" android:textSize="12dp"/>        
      <Button android:id="@+id/ServiceButton" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="@drawable/service" android:textSize="12dp" android:onClick="ServiceClickHandler"></Button>
      <Button android:id="@+id/NavigationButton" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="@drawable/navigate" android:textSize="12dp" android:onClick="NavigateClickHandler"></Button>         
</LinearLayout>

编辑,添加截图,我想在这些控件后面放置一个背景: 应用程序屏幕截图

4

1 回答 1

0

LinearLayout如果( )的唯一目的@id/lineLayout1是充当 bg 容器,则将其替换为ImageViewset android:scaleType以匹配您想要实现的缩放结果。

编辑

将其包裹在 RelativeLayout 布局中,并将 ImageView 作为 BG 容器:

<ScrollView
   xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainScrollView"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" 
   android:background="#000000" 
   android:orientation="vertical"
   android:fillViewport="true">

   <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent">
      <ImageView 
          android:id="@+id/imageView1" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:src="@drawable/beta_bg_drawable"/>

        <LinearLayout 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:background="#5500ff00" 
            android:orientation="vertical">
        </LinearLayout>

   </RelativeLayout>

</ScrollView>
于 2012-11-24T14:10:00.307 回答