0

I'm making a music player in android studio and I would like to do something like this

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

The black rectangle is the phone. I've already made the yellow part and now I have to set up the imageview as the one in the draw but I don't understand what kind of properties I have to type.

Here's the code i've made:

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

Thank you in advance and sorry for my bad English (I'm Italian).

Community
  • 1
  • 1

1 Answers1

0

First you're going to want it to fill the space in between your top and bottom layouts, so make the width/height of the ImageView to fill_parent.

Next, you'll want to give it an android:layout_weight="1" as well, so it doesn't push the bottom layout off the screen.

Now for the actual image, you'll want to add android:scaleType="centerCrop" to the ImageView. This will cause the source image to be scaled (from the center, maintaining aspect ratio) so that the width/height of the image will fill or extend beyond the boundaries of the View.

Edit: you can also remove all the layout_gravity attributes, as the layout_weight will render them useless.

Cruceo
  • 6,763
  • 2
  • 31
  • 52