我已在 linearlayout 上将图像设置为背景。这是代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainbg"
android:orientation="vertical"
android:padding="5dp"
>
问题是,图像的宽度约为 2000 像素,我不想缩小尺寸以适应屏幕,我只想显示尽可能多的背景而不是拉伸(stretch)它。
我该怎么做?
谢谢
最佳答案
在布局中添加 ImageView 并将其 scaletype 设置为 centerCrop
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/mainbg" />
</LinearLayout>
检查图像比例类型:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
关于android - 如何停止在线性布局上拉伸(stretch)背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32478186/