Android 滑动抽屉
我尝试在 Android 上使用 SlidingDrawer。
当您单击 ImageButton“handle”时,SlidingDrawer“slidingDrawerMP”应该与“coversSongLayout”线性布局重叠,但它不起作用。 有什么建议吗?
谢谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="top"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="@+id/coversSongLayout"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_weight="1">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coversLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:columnWidth="90dp"
android:numColumns="auto_fit" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
android:gravity="center" android:layout_weight="1" />
</LinearLayout>
<FrameLayout android:id="@+id/linearLayoutMP"
android:layout_height="28dp" android:gravity="bottom"
android:layout_width="fill_parent" android:background="@android:color/transparent"
android:layout_margin="0dip">
<SlidingDrawer android:id="@+id/slidingDrawerMP"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:handle="@+id/handle" android:content="@+id/content"
android:background="#aa0000">
<ImageButton android:id="@+id/handle"
android:layout_width="wrap_content" android:src="@drawable/up"
android:background="#fff" android:layout_height="wrap_content"></ImageButton>
<LinearLayout android:id="@+id/content"
android:background="#ccaaaaaa" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/currentSongLayout">
<LinearLayout android:id="@+id/coverLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:id="@+id/cover" android:src="@drawable/generic_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/songLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Song" />
</LinearLayout>
<LinearLayout android:id="@+id/artistAlbumLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Artist" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" - " />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Album" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<LinearLayout android:id="@+id/mediaControls"
android:orientation="horizontal" android:background="#ccaaaaaa"
android:layout_width="match_parent" android:layout_height="53dp">
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/prev" android:id="@+id/prev"></ImageButton>
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/play" android:id="@+id/play" />
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/next" android:id="@+id/next" />
</LinearLayout>
</LinearLayout>
Im tryng to use SlidingDrawer on android.
When you click on ImageButton "handle", SlidingDrawer "slidingDrawerMP" should overlap "coversSongLayout" Linear Layout, but it don't work.
Any suggestions?
Thank you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="top"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="@+id/coversSongLayout"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_weight="1">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coversLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:columnWidth="90dp"
android:numColumns="auto_fit" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
android:gravity="center" android:layout_weight="1" />
</LinearLayout>
<FrameLayout android:id="@+id/linearLayoutMP"
android:layout_height="28dp" android:gravity="bottom"
android:layout_width="fill_parent" android:background="@android:color/transparent"
android:layout_margin="0dip">
<SlidingDrawer android:id="@+id/slidingDrawerMP"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:handle="@+id/handle" android:content="@+id/content"
android:background="#aa0000">
<ImageButton android:id="@+id/handle"
android:layout_width="wrap_content" android:src="@drawable/up"
android:background="#fff" android:layout_height="wrap_content"></ImageButton>
<LinearLayout android:id="@+id/content"
android:background="#ccaaaaaa" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/currentSongLayout">
<LinearLayout android:id="@+id/coverLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:id="@+id/cover" android:src="@drawable/generic_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/songLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Song" />
</LinearLayout>
<LinearLayout android:id="@+id/artistAlbumLayout"
android:orientation="horizontal" android:gravity="center"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Artist" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" - " />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Unknowed Album" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<LinearLayout android:id="@+id/mediaControls"
android:orientation="horizontal" android:background="#ccaaaaaa"
android:layout_width="match_parent" android:layout_height="53dp">
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/prev" android:id="@+id/prev"></ImageButton>
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/play" android:id="@+id/play" />
<ImageButton android:layout_height="wrap_content"
android:background="@null" android:layout_width="fill_parent"
android:layout_weight="1" android:src="@drawable/next" android:id="@+id/next" />
</LinearLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
包含滑动抽屉的 FrameLayout 只有 28 dp 高,它需要与抽屉打开的尺寸一样大。通常您希望抽屉的容器与屏幕一样大。
The FrameLayout containing the sliding drawer is only 28 dp high, it needs to be as big as the opened size of the drawer. Usually you want the drawer's container to be as big as the screen.
我在线性布局中的滑动抽屉也遇到了问题。看来您的根布局应该是一个框架或相对布局,以便滑动抽屉位于其余内容之上。 (似乎也符合逻辑)。还要按照罗曼的建议检查身高。
I had problems with sliding drawer in linear layout as well. It seems the root layout of yours should be a frame or a relative layout for the sliding drawer to be on top of the rest of your content. (seems logical as well). Also check for the height as Romain sugested.