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显示出来!!!

更多相关文章

  1. Android(安卓)Webview调用系统相册实现多选图片上传
  2. android ndk 入门3 - log实现
  3. Android(安卓)轻松实现语音识别的完整代码
  4. Android(安卓)轻松实现语音识别的完整代码
  5. android 系统关机,重启
  6. Android(安卓)BLE Gatt实现原理解析(未完)
  7. android bitmap 处理
  8. 仿UC底部菜单栏实例源码
  9. Android(安卓)实现 按钮从两边移到中间动画效果

随机推荐

  1. ionic3/ionic4 要配置android ios使用一
  2. Android游戏框架
  3. 2019-02-25(android)
  4. 制作自己的android升级包(update.zip)
  5. 兼容android 9.0 明文传输(支持http请求,默
  6. 网页中android Toast效果的实现
  7. android跳转微信指定公众号界面
  8. 去除svn中方法
  9. Android(安卓)N(7.0) 遇到 android.os.File
  10. Android扫描zxing定制化界面实现扫描和图