我想在android中创建滑动抽屉,它应该放在活动的顶部,并且应该像Android通知面板一样从上到下打开。怎么做到这一点?
答案 0 :(得分:1)
默认的SlidingDrawer
类不允许这样做。您可以使用此处的Panel类来获得非常相似的内容,或者为SlidingDrawer
,内容和句柄设置180º的旋转。 注意:android:旋转支持API>等级11
http://www.ohloh.net/p/android-misc-widgets
https://github.com/IanDarwin/Android-Cookbook-Examples/tree/master/SlidingDrawer-Topdown
答案 1 :(得分:1)
如果你想从上到下有滑动抽屉,那么只需在你的项目中复制这个代码,它就是100%工作代码。
<强> main.xml中强>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#d3d3d3"
>
<SlidingDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingDrawer"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:content="@+id/content"
android:gravity="center_horizontal"
android:handle="@+id/handle"
android:orientation="vertical"
android:rotation="180" >
<LinearLayout
android:id="@+id/handle"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:gravity="right"
android:background="@+drawable/drawer_bk"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@+drawable/drawer1" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="45dp" >
<RelativeLayout
android:id="@+id/rel1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:rotation="180" >
<ImageView
android:id="@+id/ImageView04"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="visit"
android:src="@drawable/visit_icon" />
<ImageView
android:id="@+id/ImageView03"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_marginRight="35dp"
android:layout_toLeftOf="@+id/ImageView04"
android:onClick="contact_us"
android:src="@drawable/contact_icon" />
<ImageView
android:id="@+id/ImageView02"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="35dp"
android:layout_toRightOf="@+id/ImageView04"
android:onClick="logout"
android:src="@drawable/singout_icon" />
</RelativeLayout>
</RelativeLayout>
</SlidingDrawer>
<强> MainActivity.java 强>
public class MainActivity extends Activity
{
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 4000;
Button slideButton,b1, b2,b3,b4;
SlidingDrawer slidingDrawer;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//slideButton = (Button) findViewById(R.id.slideButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened()
{
// slideButton.setBackgroundResource(R.drawable.down_arrow_icon);
slidingDrawer.setBackgroundResource(R.drawable.hd_img_1);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener()
{
@Override
public void onDrawerClosed()
{
// slideButton.setBackgroundResource(R.drawable.upwar_arrow_icon);
slidingDrawer.setBackgroundColor(Color.TRANSPARENT);
}
});
}
}