SeekBar at the top of the layout in Android

I would like to reproduce the SeekBar position of the Google Music app, but I cannot find a way to do this. I've tried padding and margin with no success.

Here's what I'd like to reproduce:

And here is my actual layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <RelativeLayout
        android:id="@+id/music_player"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="#BBBBBB">

        <SeekBar
            android:id="@+id/musicSeekBar"
            android:layout_width="fill_parent"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:layout_toLeftOf="@+id/duration"
            android:layout_toRightOf="@+id/played" />

        <ToggleButton
            android:id="@+id/playPauseButton"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/ic_play_pause"
            android:textOff=""
            android:textOn="" />

        <TextView
            android:id="@+id/songName"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:layout_above="@+id/musicSeekBar"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="TextView" />

        <TextView
            android:id="@+id/played"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/playPauseButton"
            android:layout_alignBottom="@+id/playPauseButton"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/playPauseButton"
            android:text="00:00" />

        <TextView
            android:id="@+id/duration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/played"
            android:layout_alignBottom="@+id/played"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="00:00" />

        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:visibility="invisible" />

    </RelativeLayout>
</LinearLayout>

      

0


source to share


1 answer


You will need to overlap the ViewPager with a SeekBar. The easiest way to achieve this is to have the ViewPager and SeekBar in the same RelativeLayout, with the SeekBar negative android:layout_marginTop

.



In your layout, it is probably easiest to replace the LinearLayout with the RelativeLayout with three children: ViewPager, nested RelativeLayout, and Seekbar.

0


source







All Articles