首先main的xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="58dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3" >
</GridView>
</SlidingDrawer>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/slidingDrawer1"
android:layout_alignParentTop="true"
android:layout_marginLeft="83dp"
android:layout_marginTop="22dp"
android:text="TextView" />
</RelativeLayout>
然后ativity
private TextView tv;
private ImageView iv;
private GridView gv;
private SlidingDrawer sd;
private int[] icons = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher };
private String[] items = { "alert", "alert", "alert", "alert", "alert",
"alert" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
iv = (ImageView) findViewById(R.id.handle);
sd = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
gv = (GridView) findViewById(R.id.gridView1);
MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons);
gv.setAdapter(adapter);
sd.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
// TODO Auto-generated method stub
}
});
sd.setOnDrawerCloseListener(new OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
// TODO Auto-generated method stub
}
});
}
MyGridViewAdapter主要内容
public class MyGridViewAdapter extends BaseAdapter{
private Context con_;
private String [] item_;
private int [] icons_;
public MyGridViewAdapter(Context con,String [] items, int[]icons){
con_ = con;
item_ = items;
icons_ = icons;
}
@Override
public int getCount() {
return item_.length;
}
@Override
public Object getItem(int arg0) {
return item_[arg0];
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
LayoutInflater factory = LayoutInflater.from(null);
View v = factory.inflate(R.layout.textview, null);
TextView tv = (TextView) v.findViewById(R.id.textView3);
tv.setText(item_[arg0]);
return v;
}
}