2011-08-09 76 views

回答

0

做出的LinearLayout android的高度和宽度为WRAP_CONTENT在.xml文件中使用此代码

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

设置背景图像使用代码

android:background="@drawable/image" 

现在放置在图像中绘制文件

+2

他问如何确保图像不被拉伸。使用您的解决方案,如果线性布局的内容变得比图像更大,则图像将再次伸展。你如何解决这个问题? – 2014-02-04 16:58:33

4

其他解决方案是用XML定义图像,并在背景中参考此XML:Background Image Placement
就像你可以控制你的图像(背景)布局

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选项在图像的宽度和高度上保持不变。