SlidingDrawer这个类,也就是所谓的"抽屉"类。它的用法很简单,要包括handle,和content.
handle就是当你点击它的时候,content要么抽抽屉要么关抽屉。别的不多说了,具体步骤如下.
效果如下所示:
点击"抽屉"前:

点击"抽屉"后:

工程目录如下:

mail.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080"
>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/handle"
android:layout_width="88dip"
android:layout_height="44dip"
android:src="@drawable/android1" />
<GridView
android:id="@id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="90px"
android:background="#999099ff" />
</SlidingDrawer>
</LinearLayout>
image_view.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip" android:layout_width="fill_parent">
<ImageView
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@+id/ItemImage"
android:layout_height="wrap_content"
android:text="TextView01"
android:layout_centerHorizontal="true"
android:id="@+id/ItemText">
</TextView>
</RelativeLayout>
activity代码如下:
package mzz.drawer;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;
public class SlidingDrawerActivity extends Activity {
/** Called when the activity is first created. */
private GridView content = null ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
content = (GridView)findViewById(R.id.content);
ArrayList<HashMap<String,Object>> array = new ArrayList<HashMap<String,Object>>();
for(int i = 1 ; i < 14 ; i ++) {
HashMap<String , Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.icon);
map.put("ItemText", "No." + i);
array.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, array, R.layout.image_view,
new String[]{"ItemImage" , "ItemText"}, new int[]{R.id.ItemImage,R.id.ItemText});
content.setAdapter(adapter);
}
}
本文介绍如何使用 Android 的 SlidingDrawer 类实现抽屉效果。通过设置 handle 和 content 属性,结合 GridView 和自定义适配器,展示了创建交互式滑动抽屉的基本步骤。
188

被折叠的 条评论
为什么被折叠?



