如何调整背景图像?

时间:2013-09-05 06:59:58

标签: android image background

我想调整我在activity_main.xml中声明的背景图像:

android:background="@drawable/spieler_blau"

问题是整个屏幕都充满了这张图片,我希望屏幕左侧有一个小的空白区域。像那样:

enter image description here

任何解决方案?提前谢谢。

3 个答案:

答案 0 :(得分:2)

Here is output

您可以使用android:layout_marginLeft="20dp"。您可以根据要求设置保证金。

或者你也可以在xml中创建一个空白View和一个ImageView并给它赋予权重。

示例:

1)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/expandable"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="horizontal" >



    <View  android:layout_weight="1"
         android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       android:layout_weight="0.5"
        android:background="@drawable/ic_launcher" />

2)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/expandable"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="horizontal" >



    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="20dp"
        android:background="@drawable/ic_launcher" />

</LinearLayout>

答案 1 :(得分:1)

如果您需要留在左侧的空间, 有可能的方法,

  1. 设置Imageview SRC,而不是背景,并在左侧给出填充
  2. 使用左侧的透明空间创建背景可绘制
  3. 或者您创建自定义视图

答案 2 :(得分:0)

您可以使用android:paddingLeft属性在图片布局左侧添加填充来执行此操作:

<ImageView android:background="@drawable/spieler_blau"
   android:paddingLeft="10dp"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"/>