[英]Using the Glide library to load image to fill up the screen
我正在尝试使用 glide 库加载背景图像,以便它填满整个屏幕。 我有以下布局的 xml。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:adjustViewBounds="true"
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include layout="@layout/signup_layout"/>
</RelativeLayout>
我在使用 Glide 库的活动中的代码是
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loginscreen);
// Setup the email field
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
// Setup password field
mPasswordView = (EditText) findViewById(R.id.password);
ImageView imageView = (ImageView) findViewById(R.id.backgroundImage);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Glide.with(this)
.load(R.drawable.green_field)
.override(width,height)
.centerCrop()
.into(imageView);
运行代码后,图像在屏幕的左侧和右侧都有空白,但它填满了图像的整个高度。 我试图同时使用 .fitCenter() 和 .centerCrop() 但图像变得像素化。
因为你用过它不能填满整个屏幕
android:adjustViewBounds="true"
哪些订单( 文档):
如果您希望 ImageView 调整其边界以保留其 drawable 的纵横比,请将其设置为 true。
这也是 API17 之前的错误,如上述文档警告。
如果你想填满整个屏幕,你应该删除android:adjustViewBounds
并考虑使用
android:scaleType="fitCenter"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.