1.创建一个xml布局文件,layout
实现布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/singinux_1302_title"
layout="@layout/singinus_base_title" />
<LinearLayout
android:id="@+id/linear_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<include
android:id="@+id/singinux_1302_bottom"
android:layout_alignParentBottom="true"
layout="@layout/singinus_base_bottom" />
</LinearLayout>
<LinearLayout
android:id="@+id/linea_center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/linear_bottom"
android:layout_below="@id/singinux_1302_title"
android:background="@drawable/bg_contents"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="25dip"
android:background="@drawable/bg_result"
android:orientation="vertical" >
<!-- floor_1 -->
<ImageView
android:id="@+id/img_floor1_1"
android:layout_width="match_parent"
android:layout_height="70dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="40dip"
android:scaleType="fitXY"
android:src="@drawable/img_result_01" />
<!-- 第二层 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img_floor2_1"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_weight="2"
android:paddingLeft="10dip"
android:scaleType="fitXY"
android:src="@drawable/img_result_02" />
<ImageView
android:id="@+id/img_floor2_2"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_marginLeft="10dip"
android:layout_weight="3"
android:paddingRight="10dip"
android:scaleType="fitXY"
android:src="@drawable/img_result_03" />
</LinearLayout>
<!-- 第三层 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img_floor3_1"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_weight="1"
android:paddingLeft="5dip"
android:scaleType="fitXY"
android:src="@drawable/img_result_03" />
<ImageView
android:id="@+id/img_floor3_2"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_marginLeft="5dip"
android:layout_weight="1"
android:paddingRight="5dip"
android:scaleType="fitXY"
android:src="@drawable/img_result_03" />
<ImageView
android:id="@+id/img_floor3_3"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_marginRight="10dip"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="@drawable/img_result_03" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
2. 自定义一个style方格的对话框,style文件dialogtheme
<style name="dialogtheme" parent="@android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<!-- 隐藏标题栏 -->
<item name="android:windowBackground">@color/clarity</item>
<!-- 这儿也很重要啊,我这儿用了一张透明的.9.png的图,当然用#00000000也是可以的,否则的话这儿出来后有一个黑色的背景 -->
<item name="android:backgroundDimEnabled">false</item>
</style>
3.调用处的使用方法:
final Dialog dialog=new Dialog(PopWindowMainActivity.this,R.style.dialogtheme);
View v=LayoutInflater.from(this).inflate(R.layout.singinus_1303, null);
ImageView img_floor1_1=(ImageView)v.findViewById(R.id.img_floor1_1);
ImageView img_floor2_1=(ImageView)v.findViewById(R.id.img_floor2_1);
ImageView img_floor2_2=(ImageView)v.findViewById(R.id.img_floor2_2);
ImageView img_floor3_1=(ImageView)v.findViewById(R.id.img_floor3_1);
ImageView img_floor3_2=(ImageView)v.findViewById(R.id.img_floor3_2);
ImageView img_floor3_3=(ImageView)v.findViewById(R.id.img_floor3_3);
//title_right
ImageView title_right=(ImageView)v.findViewById(R.id.title_right);
//title_left
ImageView title_left=(ImageView)v.findViewById(R.id.title_left);
title_right.setVisibility(View.GONE);
img_floor1_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
img_floor2_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
img_floor2_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
img_floor3_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
img_floor3_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
img_floor3_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(PopWindowMainActivity.this, "你点击了", 1000).show();
}
});
title_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.setContentView(v);
dialog.show();
}
这样的话,就可以实现一个自定义的对话框了,通过xml创建view,再对view上面的控件定制事件,最后通过dialog显示出来!!!