如何使一个Android SlidingDrawer从左侧滑出?
-
16-09-2019 - |
题
我用我的应用程序,它有它的处理器在纵向模式放置在底部时slidingDrawer
。当用户切换为横向模式(宽屏)我想有位于左侧的处理程序。当我改变从垂直到水平方向,处理程序放在右边。
我已经定义我的布局XML这样的:
<SlidingDrawer
android:id="@+id/l_drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/l_handle"
android:content="@+id/l_content"
android:orientation="horizontal"
android:layout_gravity="left"
>
任何人都有如何使它滑动由左到右的想法?
解决方案
我不认为你可以,也许比其他通过抓住SlidingDrawer
源代码,更改它,并使用您的修改后的版本。你同样不能使从顶部下降一个SlidingDrawer
。
其他提示
我已经找到了一种简单的方法来做到这一点。所有你需要做的是设置的180度旋转的slidingDrawer,内容和手柄。 您同样可以使一个SlidingDrawer从顶部下降,像我一样的此处。
看我的例子在这里,先从右到左,才能够看到的差异。
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:src="@drawable/ic_launcher" />
</SlidingDrawer>
现在看看我改变,使其从左侧滑出。
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:handle="@+id/handle"
android:content="@+id/content"
android:rotation="180">
<LinearLayout android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:rotation="180" />
</LinearLayout>
<ImageView android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:src="@drawable/ic_launcher"
android:rotation="180" />
</SlidingDrawer>
请注意,我还创建了一个的LinearLayout设置为手柄,并没有改变它的旋转,但我改变了旋转它的孩子。这是为了防止小问题我有,但一切工作正常,它就是简单。
我重写了一个类到并使其我的开源库的一部分。这一个星期我花了几乎得到它的权利。请看看我的 SlidingTray 在 Aniqroid 开源的Android库。
http://aniqroid.sileria.com/doc/api
查找在上述链接SlidingTray类下载链接,文档
(披露:我项目的维护者)
您可以使用张贴在这个答案的代码:的Android SlidingDrawer从顶部一>
所提供的解决方案具有设置Slidingdrawer的取向以xml也很简单,只需要1类,并在一些attrs.xml增加和稳定的,因为它是从机器人会Slidingdrawer衍生自SDK。我还讨论了为什么我没有选择在互联网上找到其他流行库/解决方案/ SO。
<强>快速链接到要旨: MultipleOrientationSlidingDrawer(源&示例)@要旨 强>