2016-03-08 67 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