安卓裁剪背景 [英] Android crop background
问题描述
我有一个 LinearLayout
,宽度设置为 fill_parent
,高度设置为 wrap_content
.现在我想给它一个 png 文件的背景,但是以传统方式这样做会导致 LinearLayout
调整大小以显示整个背景而不是裁剪附加部分.
I have a LinearLayout
with width set to fill_parent
and height to wrap_content
. Now I want to give it a background from a png file, but doing it in a traditional way causes the LinearLayout
to resize in order to show the whole background instead of cropping the additional part.
如何设置 LinearLayout
的背景使其不会调整大小?
How can I set the background of LinearLayout
so it won't resize?
谢谢
推荐答案
看来只有使用 ImageView
并相应地设置 scaleType
参数才能实现.一个快速的解决方法是使用 FrameLayout
并将 ImageView
放在另一个具有透明背景的布局下.
It appears that such thing is achievable only using the ImageView
and setting the scaleType
parameter accordingly. A quick workaround is to use FrameLayout
and put the ImageView
under another layout with transparent background.
代码:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background" />
</FrameLayout>
这篇关于安卓裁剪背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!