如何设置背景不被拉伸?

时间:2011-08-09 12:18:48

标签: android

请建议如何将图片放置为LinearLayout的背景,以便此图片看起来像原样,不会拉伸,标题或其他内容。

3 个答案:

答案 0 :(得分:4)

其他解决方案是在XML中定义您的图像,并在您的背景上引用此XML,如下所述:Background Image Placement
像这样你可以控制你的图像(背景)布局

答案 1 :(得分:0)

如果线性布局的内容小于图像高度,则Jojo的解决方案可能有效。 如果我添加两个或自动编辑文本,图像开始拉伸。如果您仍想避免并在后台进行imageview,请使用以下xml布局。

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <ImageButton android:id="@+id/imageButton1" android:src="@drawable/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@null"></ImageButton>
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="100px"></Button>
</RelativeLayout>

因为只有图像按钮的src选项与图像的宽度和高度保持不变。

答案 2 :(得分:-1)

使用.xml文件中的此代码将LinearLayout的android高度和宽度设置为wrap_content

android:layout_height="wrap_content"  
android:layout_width="wrap_content"  

将背景设置为图像使用代码

android:background="@drawable/image"

现在将图像放在可绘制文件中

相关问题