我想调整我在activity_main.xml中声明的背景图像:
android:background="@drawable/spieler_blau"
问题是整个屏幕都充满了这张图片,我希望屏幕左侧有一个小的空白区域。像那样:
任何解决方案?提前谢谢。
答案 0 :(得分:2)
您可以使用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)
如果您需要留在左侧的空间, 有可能的方法,
答案 2 :(得分:0)
您可以使用android:paddingLeft
属性在图片布局左侧添加填充来执行此操作:
<ImageView android:background="@drawable/spieler_blau"
android:paddingLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>