Android RelativeLayout拉伸背景

时间:2016-08-09 05:41:14

标签: java android background relativelayout

所有。 这是我的布局代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@mipmap/backgroung"
    tools:context=".MainScreen">


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30pt"
        android:text="@string/level1"
        android:onClick="@string/level1"
        android:id="@+id/level1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="60pt"
        android:text="@string/level2"
        android:id="@+id/level2"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="90pt"
        android:text="@string/level3"
        android:id="@+id/level3"/>

看起来像是:

enter image description here

我希望打孔照片会在白色背景上延伸。

感谢帮助者!

3 个答案:

答案 0 :(得分:1)

最好在这里使用9patch图像。其中打孔区域可以是恒定的,并且图像可以与蓝色区域一起拉伸。这样你就不会因为拉伸而面临图像模糊的问题。您可以找到一些如何从youtube创建9patch的好例子。这是一个sample

答案 1 :(得分:1)

我明白了, 添加新图像资源时,它会调整图像大小并裁剪为白色边框。 需要将整张照片硬拷贝粘贴到可绘制文件夹中。

答案 2 :(得分:0)

在您的RelativeLayout中,您是否看到android:paddingTop和底部/左/右?删除所有这些或更改为="0dp"

在按钮前将图像移动到<ImageView/>

并使用android:scaleType="fitXY"

哦,确保你的照片没有任何空白边框。