问题
I would like to reproduce the SeekBar position of Google Music application but I can’t find a way to do it. I’ve tried padding and margin without success.
Here is 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>
回答1:
You'll need to overlap the ViewPager with the SeekBar. The easiest way to accomplish that is by having the ViewPager and the SeekBar in the same RelativeLayout, with the SeekBar having a negative android:layout_marginTop
.
In your layout, it's probably easiest to replace LinearLayout with a RelativeLayout with three children: the ViewPager, the nested RelativeLayout and the Seekbar.
来源:https://stackoverflow.com/questions/20952966/seekbar-at-the-top-of-the-layout-in-android