【发布时间】:2013-02-26 17:47:04
【问题描述】:
请告知如何将图像放置为LinearLayout 的背景,以便该图像看起来像原样,而不是拉伸、标题或其他内容。
【问题讨论】:
标签: android
请告知如何将图像放置为LinearLayout 的背景,以便该图像看起来像原样,而不是拉伸、标题或其他内容。
【问题讨论】:
标签: android
其他解决方案是在 XML 中定义您的图像并在您的背景上引用此 XML,如下所述:Background Image Placement
像这样你可以控制你的图像(背景)布局
【讨论】:
如果线性布局的内容小于图像高度,Jojo 的解决方案可能会起作用。 如果我添加两个或自动编辑文本,图像开始拉伸。如果您仍然想避免并在后台使用图像视图,请使用以下 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 选项对图像的宽度和高度保持不变。
【讨论】:
使用 .xml 文件中的此代码将 android 的 LinearLayout 的高度和宽度转换为 wrap_content
android:layout_height="wrap_content"
android:layout_width="wrap_content"
为图像设置背景使用代码
android:background="@drawable/image"
现在将图像放入可绘制文件中
【讨论】: