【发布时间】:2020-05-15 09:59:57
【问题描述】:
我正在尝试使用 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() 但图像变得像素化。
【问题讨论】:
标签: java android android-glide