2016-03-08 114 views
0

我在Android Studio中製作一個音樂播放器,我想這樣做如何設置ImageView的尺寸

Here's an ugly draw of what I'm attempting to do

黑色矩形是手機。我已經制作了黃色部分,現在我必須將imageview設置爲draw中的一個,但我不明白我必須輸入哪種屬性。

這是我所做的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<include 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    layout="@layout/song" 
    android:layout_gravity="top" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/img_album_cover" 
    android:layout_gravity="center" /> 

<include 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    layout="@layout/song_playback_buttons" 
    android:layout_gravity="bottom"/> 

</LinearLayout> 

預先感謝您爲我的英語不好(我是意大利人)對不起。

回答

1

首先,您要讓它填充頂部和底部佈局之間的空間,因此請將ImageView的寬度/高度填充爲fill_parent。

接下來,您還需要給它一個android:layout_weight="1",因此它不會將底部佈局從屏幕上推下。

現在爲實際圖像,您需要將android:scaleType="centerCrop"添加到ImageView。這將導致源圖像縮放(從中心,保持縱橫比),以便圖像的寬度/高度將填充或擴展到視圖的邊界之外。

編輯:你也可以刪除所有的layout_gravity屬性,因爲layout_weight會使它們無用。

+0

哇謝謝你,這是非常有用的! 現在它似乎很好! –

+0

很高興能幫到你! – Guardanis