Lea*_*oid 31
我找到了一种简单的方法.您所要做的就是为slidingDrawer,内容和句柄设置180º的旋转.通过示例更容易理解,所以看看我做了什么:
首先,我将从底部到顶部向您展示我的旧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="vertical"
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>
Run Code Online (Sandbox Code Playgroud)
现在看看我所做的改变,设置180度的旋转
<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="vertical"
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>
Run Code Online (Sandbox Code Playgroud)
请注意,我还创建了一个LinearLayout来设置为句柄,并没有改变它的旋转,但我更改了它的子项的旋转.这是为了防止我遇到的一个小问题,但一切都很好,而且很简单.
默认SlidingDrawer类不允许这样做.您可以使用Panel此处的类来获得非常相似的内容:http:
//code.google.com/p/android-misc-widgets/
http://www.ohloh.net/p/android-misc-widgets
我对这里提供的解决方案非常不满意:
Panel来自http://code.google.com/p/android-misc-widgets/的课程使用起来非常不直观,并且还有错误和视觉故障(无法用于高效使用)而且根本没有文档SlidingTray来自http://aniqroid.sileria.com/doc/api/的课程嵌套在需要太多依赖的lib中,对我来说,我根本没有让它工作android:rotation="180"需要API等级11,我的目标是10.(对各自的开发者没有冒犯,试图在这里客观)
所以我的解决方案是从这个lib http://aniqroid.sileria.com/doc/api/(Ahmed Shakil)中提取SlidingTray并重构一下,因为它需要在Ahmed的lib中使用一些怪癖.是基于Androids自己的,所以我猜它是稳定的.我的修改包括我调用的一个类,你必须在attrs.xml中添加declare-styleables.除此之外,它具有与SlidingDrawer几乎相同的用法以及
额外的"orientation"属性.SlidingTraySlidingDrawerMultipleOrientationSlidingDrawer
看看:MultipleOrientationSlidingDrawer(来源和示例)@gist
这是一个用法示例(也在要点中提供)
<your.app.MultipleOrientationSlidingDrawer
xmlns:custom="http://schemas.android.com/apk/res-auto/your.app"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:handle="@+id/handle_c"
custom:content="@+id/content_c"
custom:orientation="top">
<RelativeLayout
android:id="@id/handle_c"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#333333">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Handle Text"
android:gravity="left|center_vertical"/>
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@id/content_c"
android:background="#555555">
<ListView
android:id="@+id/listview_credits"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</your.app.MultipleOrientationSlidingDrawer>
Run Code Online (Sandbox Code Playgroud)
免责声明:所有学分都归各自开发.我没有直接测试这个解决方案,它在用XML设置的TOP和BOTTOM时效果很好.我没有尝试以编程方式使用它.
我必须为我的一个项目做同样的事情,最后我为此编写了自己的小部件.我称之为SlidingTray现在是我的开源Aniqroid库的一部分.
http://aniqroid.sileria.com/doc/api/ (查看底部的下载或使用谷歌代码项目查看更多下载选项:http://code.google.com/p/aniqroid/downloads/list)
课程文档在这里:http://aniqroid.sileria.com/doc/api/com/sileria/android/view/SlidingTray.html
| 归档时间: |
|
| 查看次数: |
32787 次 |
| 最近记录: |