2016-04-25 95 views
2

我想加载一个背景使用滑动库的图像,以便它填满整个屏幕。我有以下xml的布局。使用Glide库加载图像来填满屏幕

<?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> 

我对在我使用滑翔库活动代码是

@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(),但Image变得像素化。

回答

1

它可以不填,因为你使用

android:adjustViewBounds="true" 

这令整个屏幕(docs):

如果你想的ImageView其边界调整 保存设置为true的其可绘制的长宽比为

此外,这是前API17上的错误,如上文档警告。

如果你想填补整个屏幕,你应删除android:adjustViewBounds或许可以考虑使用

android:scaleType="centerFit"