【问题标题】:How to set imageview dimensions如何设置图像视图尺寸
【发布时间】:2016-03-08 21:19:40
【问题描述】:

我正在 android studio 中制作音乐播放器,我想做这样的事情

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>

提前谢谢你,对不起我的英语不好(我是意大利人)。

【问题讨论】:

    标签: android android-layout audio-player albumart android-music-player


    【解决方案1】:

    首先,您希望它填充顶部和底部布局之间的空间,因此将 ImageView 的宽度/高度设置为 fill_parent。

    接下来,您还需要给它一个android:layout_weight="1",这样它就不会将底部布局推离屏幕。

    现在对于实际图像,您需要将android:scaleType="centerCrop" 添加到 ImageView。这将导致源图像被缩放(从中心,保持纵横比),以便图像的宽度/高度将填充或超出视图的边界。

    编辑:您还可以删除所有 layout_gravity 属性,因为 layout_weight 会使它们变得无用。

    【讨论】:

    • 哇,谢谢,这非常有用!现在看来效果很好!
    猜你喜欢
    • 1970-01-01
    • 2011-10-14
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多