这东西很简单:
(1)我的Dialog布局history.xml:
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff" >
android:layout_height="32dp"
android:background="@drawable/title"
android:gravity="center"
android:text="打开记录"
android:textSize="20dp"
android:textColor="#ffffff" >
android:layout_width="280dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:horizontalSpacing="20dp"
android:verticalSpacing="20dp"
android:numColumns="2"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >
history_item_content.xml:
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="false" />
(2)我的Dialog:
package com.zx.drawingborad;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class BackGroupDialog extends Dialog implements OnItemClickListener {
// private PaintView paintView;
int drawble[] = { R.drawable.ditu };
public BackGroupDialog(Context context, int mydialogstyle) {
super(context, mydialogstyle);
// this.paintView = paintView;
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
GridView bgview = (GridView) findViewById(R.id.historypath);
bgview.setAdapter(new DrawAdapter());
bgview.setOnItemClickListener(this);
}
class DrawAdapter extends BaseAdapter {
public DrawAdapter() {
// TODO Auto-generated constructor stub
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return drawble.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = (ImageView) getLayoutInflater().inflate(
R.layout.history_item_content, null);
}
((ImageView) convertView).setImageResource(drawble[arg0]);
((ImageView) convertView).setBackgroundColor(Color.YELLOW);
return convertView;
}
}
@Override
public void onItemClick(AdapterView> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
this.dismiss();
}
}
(3)在res-values-styles.xml中添加:
(4)在Activity中使用:
new BackGroupDialog(this,R.style.ShareDialog).show();