2016-04-25 96 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"