Dialog布局


dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="290dp"
    android:layout_height="wrap_content"
    android:background="@drawable/dialog_bg"
    android:orientation="vertical"
    android:paddingBottom="28dp"
    android:paddingLeft="18dp"
    android:paddingRight="18dp"
    android:paddingTop="18dp" >
    <ImageView
        android:id="@+id/iv_chat_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="5dp"
        android:src="@drawable/dialog_close_selector" />
    <TextView
        android:id="@+id/tv_chat_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/iv_chat_cancel"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@id/iv_chat_cancel"
        android:layout_toLeftOf="@id/iv_chat_cancel"
        android:ellipsize="end"
        android:gravity="left|center_vertical"
        android:singleLine="true"
        android:text="bqt"
        android:textColor="#666666"
        android:textSize="15sp" />
      <GridView
        android:id="@+id/gv_chat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_chat_name"
        android:layout_marginTop="18dp"
        android:cacheColorHint="#00000000"
        android:listSelector="#00000000"

android:numColumns="3" />

</RelativeLayout>


item_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/item_dialog_bg"
    android:orientation="vertical"
    android:paddingBottom="10dp"
    android:paddingTop="10dp" >
    <TextView
        android:id="@+id/tv_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:drawablePadding="10dp"
        android:drawableTop="@drawable/chat_my_money"
        android:ellipsize="end"
        android:gravity="center"
        android:singleLine="true"
        android:text="对她说"
        android:textColor="#808080"
        android:textSize="15sp" />

</LinearLayout>


item_dialog_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"><shape>
            <solid android:color="#f5f5f5" />
            <corners android:radius="3dp" />
        </shape></item>
    <item><shape>
            <corners android:radius="3dp" />
            <solid android:color="#fff" />
        </shape></item>

</selector>


Dialog代码

public class ChatDialog extends Dialog implements OnClickListener, OnItemClickListener {

    private Context context;
    private Person person;//接收一个操作的对象
    private ImageView iv_chat_cancel;//取消
    private TextView tv_chat_name;//标题
    private GridView mGv_chat;
    //初始化GridView的条目
    private final List<DialogData> mDatas = new ArrayList<DialogData>() {
        {
            add(new DialogData(R.drawable.chat_my_money, "充值"));
            add(new DialogData(R.drawable.chat_my_attend, "我的关注"));
            add(new DialogData(R.drawable.chat_my_alter_nickname, "修改昵称"));
            add(new DialogData(R.drawable.chat_my_brocast, "发广播"));
        }
    };
    public ChatDialog(Context context, Person person) {
        super(context, R.style.DialogTheme);
        initView(context, person);
    }
    public ChatDialog(Context context, int theme, Person person) {
        super(context, R.style.DialogTheme);
        initView(context, person);
    }
    public void initView(Context context, Person person) {
        this.context = context;
        this.person = person;
        setContentView(R.layout.dialog);
        tv_chat_name = (TextView) findViewById(R.id.tv_chat_name);
        mGv_chat = (GridView) findViewById(R.id.gv_chat);
        iv_chat_cancel = (ImageView) findViewById(R.id.iv_chat_cancel);
        iv_chat_cancel.setOnClickListener(this);
        tv_chat_name.setOnClickListener(this);
        mGv_chat.setOnItemClickListener(this);
        mGv_chat.setAdapter(new MAdpater());
        tv_chat_name.setText(person.getName());
    }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        whatOnItemClick(mDatas.get(arg2).resid);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.tv_chat_name://昵称
            whatOnNickNameClick();
            break;
        case R.id.iv_chat_cancel://取消
            dismiss();
            break;
        default:
            break;
        }
    }
    /**
     * 点击GridView不同条目时触发的事件,如要自定义,请覆盖此方法
     */
    public void whatOnItemClick(int id) {
        switch (id) {
        case R.drawable.chat_my_money:
            break;
        case R.drawable.chat_my_attend:
            break;
        case R.drawable.chat_my_alter_nickname:
            break;
        case R.drawable.chat_my_brocast:
            break;
        default:
            break;
        }
        this.dismiss();
    }
    /**
     * 点击昵称时触发的事件,如要自定义,请覆盖此方法
     */
    public void whatOnNickNameClick() {
        Toast.makeText(context, "你点击了昵称", Toast.LENGTH_SHORT).show();
    }
    /**
     * 返回传入的对象
     */
    public Person getTalker() {
        return person;
    }
    //*****************************************************************************************************
    /**
     * 内部类,封装GridView中的条目的信息
     */
    private class DialogData {
        public int resid;//图片
        public String text;//描述
        public DialogData(int resid, String text) {
            this.resid = resid;
            this.text = text;
        }
    }
    /**
     * GridView的适配器
     */
    private class MAdpater extends BaseAdapter {
        @Override
        public int getCount() {
            return mDatas.size();
        }
        @Override
        public Object getItem(int position) {
            return mDatas.get(position);
        }
        @Override
        public long getItemId(int position) {
            return position;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_dialog, null);
            TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
            tv_content.setCompoundDrawablesWithIntrinsicBounds(0, mDatas.get(position).resid, 0, 0); //图标的宽高将会设置为固有宽高
            tv_content.setText(mDatas.get(position).text);
            return view;
        }
    }
}
/**
 * 要操作的对象
 */
class Person {
    public  String name;
    public  int age;

}


重新被一同事修改

public class LiveAudiencePopupView implements OnClickListener, OnItemClickListener {
    private Context mContext;
    private List<ChatDialogData> mDatas;
    private Dialog mPopupChatDialog;
    private RelativeLayout mRelativeLayout;
    private RelativeLayout.LayoutParams mLayoutParams;
    private GridView mGv_chat;
    private Runnable dialogDimissRunnable;
    private Handler mHandler;
    private boolean isQuit = false;
    public LiveAudiencePopupView(Context context, WSChater user) {
        mContext = context;
        mDatas = new ArrayList<ChatDialogData>();
        initView(user);
    }
    public void onExecute(int type) {
    }
    public void show() {
        if (mPopupChatDialog != null && !mPopupChatDialog.isShowing()) mPopupChatDialog.show();
    }
    private void initView(WSChater user) {
        View view = ((Activity) mContext).getLayoutInflater().inflate(R.layout.live_chat_dialog, null);
        mRelativeLayout = (RelativeLayout) view.findViewById(R.id.ll_root);
        mLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);

        int width = ApplicationUtil.getScreenWidth(mContext);
        int height = ApplicationUtil.getScreenHeight(mContext);
        int statusBarHeight = ApplicationUtil.getStatusBarHeight((Activity) mContext);//获取状态栏的高度
        mLayoutParams.width = width;
        mLayoutParams.height = height - statusBarHeight;

        TextView tv_chat_name = (TextView) view.findViewById(R.id.tv_chat_name);
        mGv_chat = (GridView) view.findViewById(R.id.gv_chat);
        ImageButton ib_chat_cancel = (ImageButton) view.findViewById(R.id.ib_chat_cancel);
        ImageView iv_head = (ImageView) view.findViewById(R.id.iv_head);
        BadgeView view_badge = (BadgeView) view.findViewById(R.id.view_badge);
        if (user != null) {
            if (user.getUid() == AppUser.getInstance().getUser().getuId()) {
                mDatas.add(new ChatDialogData(R.drawable.chat_my_money, "充值"));
                mDatas.add(new ChatDialogData(R.drawable.chat_my_attend, "我的关注"));
                mDatas.add(new ChatDialogData(R.drawable.chat_my_alter_nickname, "修改资料"));
            } else {
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_data, "Ta的档案"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_public, "公开对Ta说"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_private, "悄悄对Ta说"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_send_gift, "送礼给Ta"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_kick, "踢出半小时"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_gag, "禁言半小时"));
                mDatas.add(new ChatDialogData(R.drawable.ichat_talking_inform, "举报"));
            }
            ImageHelper.LoadCircleImage(user.getAvatar_url(), iv_head, R.drawable.img_user_icon);
            view_badge.setBadgeInfo(user);
            tv_chat_name.setText(user.getNickName());
        }

        mGv_chat.setLayoutAnimation(getAnimPopupController());
        mGv_chat.setAdapter(new LiveAudiencePopupViewAdapter(mDatas, mContext));
       
        mRelativeLayout.setLayoutParams(mLayoutParams);
        mRelativeLayout.setLayoutAnimation(getAnimPopupController());
        mPopupChatDialog = new Dialog(mContext, R.style.HeadlineGiftDialogTheme);
        mPopupChatDialog.setContentView(mRelativeLayout, mLayoutParams);
        mPopupChatDialog.setCanceledOnTouchOutside(true);

        Window window = mPopupChatDialog.getWindow();
        WindowManager.LayoutParams wml = window.getAttributes();
        wml.gravity = Gravity.TOP;
        window.setAttributes(wml);

        if (dialogDimissRunnable == null) {
            dialogDimissRunnable = new Runnable() {
                @Override
                public void run() {
                   if (mPopupChatDialog != null && mPopupChatDialog.isShowing()) mPopupChatDialog.dismiss();
                }
            };
        }
        ib_chat_cancel.setOnClickListener(this);
        mRelativeLayout.setOnClickListener(this);
        mGv_chat.setOnItemClickListener(this);
    }
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ib_chat_cancel || v.getId() == R.id.ll_root) {
            if (mPopupChatDialog != null && mPopupChatDialog.isShowing() && mRelativeLayout != null && !isQuit) {
                isQuit = true;
                mRelativeLayout.clearAnimation();
                mRelativeLayout.setLayoutAnimation(getAnimDismissController());
                mPopupChatDialog.setContentView(mRelativeLayout, mLayoutParams);
                mGv_chat.clearAnimation();
                mGv_chat.setLayoutAnimation(getAnimDismissController());
                mRelativeLayout.setLayoutAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }
                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mPopupChatDialog.dismiss();
                        isQuit = false;
                        if (mHandler != null) {
                            mHandler.removeCallbacksAndMessages(null);
                            mHandler = null;
                        }
                    }
                });
            }
        }
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
        if (mPopupChatDialog != null && mPopupChatDialog.isShowing()) {
            mRelativeLayout.clearAnimation();
            mRelativeLayout.setLayoutAnimation(getAllViewDismissAnimation());
            mPopupChatDialog.setContentView(mRelativeLayout, mLayoutParams);
            mRelativeLayout.setLayoutAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    if (mHandler == null) {
                        mHandler = new Handler();
                        mHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mPopupChatDialog.dismiss();
                            }
                        }, 400);
                    }
                }
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
                @Override
                public void onAnimationEnd(Animation animation) {
                    onExecute(mDatas.get(position).getResid());
                }
            });
        }
    }
    /** 
     * 弹出时,Layout动画 
     */
    private static LayoutAnimationController getAnimPopupController() {
        AnimationSet set = new AnimationSet(true);
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(500);
        set.addAnimation(animation);
        animation = new TranslateAnimation(0, 0, ApplicationUtil.dip2px(50), 0);
        animation.setDuration(500);
        set.addAnimation(animation);
        set.setInterpolator(new AccelerateInterpolator());
        LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        return controller;
    }
    /**
     *  单个消失时的动画
     * @return
     */
    private LayoutAnimationController getAnimDismissController() {
        AnimationSet set = new AnimationSet(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        alphaAnimation.setDuration(500);
        set.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, ApplicationUtil.dip2px(50));
        translateAnimation.setDuration(500);
        set.addAnimation(translateAnimation);
        set.setFillAfter(true);
        LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
        controller.setInterpolator(new AccelerateInterpolator());
        controller.setOrder(LayoutAnimationController.ORDER_REVERSE);
        return controller;
    }
    /**
     *  整个 View 的动画
     */
    private LayoutAnimationController getAllViewDismissAnimation() {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        alphaAnimation.setDuration(100);
        alphaAnimation.setFillAfter(true);
        LayoutAnimationController controller = new LayoutAnimationController(alphaAnimation);
        controller.setInterpolator(new AccelerateInterpolator());
        controller.setOrder(LayoutAnimationController.ORDER_REVERSE);
        return controller;
    }

}


调用

        final WSChater bean =(WSChater) v.getTag();
        if (!isDialogShow && !bean.equals("") && bean != null) {
            new LiveAudiencePopupView(context, bean){
                public void onExecute(int type) {
                    switch(type){
                    case R.drawable.ichat_talking_data:   // Ta的档案
                        ((LiveRoomActivity)context).onAudienceExpanClick(0, bean);
                        break;
                    case R.drawable.ichat_talking_public:  // 公开对Ta说
                        ((LiveRoomActivity)context).onAudienceExpanClick(1, bean);
                        break;
                    case R.drawable.ichat_talking_private:   // 悄悄对Ta说
                        ((LiveRoomActivity)context).onAudienceExpanClick(2, bean);
                        break;
                    case R.drawable.ichat_talking_kick:    // 踢人
                        ((LiveRoomActivity)context).onAudienceExpanClick(3, bean);
                        break; 
                    case R.drawable.ichat_talking_gag:    // 禁言
                        ((LiveRoomActivity)context).onAudienceExpanClick(4, bean);
                        break;
                    case R.drawable.ichat_talking_send_gift:  // 送礼给Ta
                        ((LiveRoomActivity)context).onAudienceExpanClick(5, bean);
                        break;
                    case R.drawable.ichat_talking_inform:    // 举报
                        ((LiveRoomActivity)context).onAudienceExpanClick(6, bean);
                        break;
                    case R.drawable.chat_my_money: // 充值
                        PayUtil.pay(context, new IMoneyChanged() {
                            @Override
                            public void onMoneyChanged(boolean result, String msg) {
                                
                            }
                        });
                        break;
                    case R.drawable.chat_my_attend: // 我的关注
                        ApplicationUtil.jumpToActivity(context, MyAttendActivity.class, null);
                        break;
                    case R.drawable.chat_my_alter_nickname: // 修改昵称
                        ApplicationUtil.jumpToActivity(context, UserInfoActivity.class, null);
                        break;
                        
                    default:
                        break;
                    }
                };
            }.show();

}


/**

     * 观众榜控件点击事件
     */
    public void onAudienceExpanClick(final int type, final WSChater bean) {
        if (bean != null) {
            switch (type) {
            case 0: // 档案。如果是自己弹出土司,否则调到用户档案界面
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) AppUtil.goToUser(this, bean.getUid());
                break;
            case 1: // 公开对Ta说
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    mLiveMessage.getLiveMessageTabsFraments().setTabPager(0);
                    mLiveInput.setPublicChat(true);
                    mLiveInput.addTalkerData(bean);
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            setDisplayEnum(LiveAnimEnum.LAE_INPUT_TEXT_V2);
                        }
                    }, 300);
                }
                break;
            case 2: // 悄悄对Ta说
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    mLiveMessage.getLiveMessageTabsFraments().setTabPager(0);
                    mLiveInput.setPublicChat(false);
                    mLiveInput.addTalkerData(bean);
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            setDisplayEnum(LiveAnimEnum.LAE_INPUT_TEXT_V2);
                        }
                    }, 300);
                }
                break;
            case 3: // 踢人
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    if (isLogin()) {
                        mLiveInput.setPublicChat(true);
                        mLiveWebSocket.sendKick(String.valueOf(bean.getUid()));
                    }
                }
                break;
            case 4: // 禁言
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    if (isLogin()) {
                        mLiveInput.setPublicChat(true);
                        mLiveWebSocket.sendGag(String.valueOf(bean.getUid()));
                    }
                }
                break;
            case 5: // 送礼
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    if (mLiveGift != null) {
                        mLiveGift.AddReceiver(bean);
                        setDisplayEnum(LiveAnimEnum.LAE_GIFT);
                    }
                }
                break;
            case 6: // 举报
                if (!chaterIsSelf(bean.getUid(), "这是你自己哦~")) {
                    AppUtil.jumpToInformActivity(LiveRoomActivity.this, bean);
                }
                break;
            }
        }

}


95秀-弹窗+listview+动画 示例的更多相关文章

  1. XamarinAndroid组件教程RecylerView适配器设置动画示例

    XamarinAndroid组件教程RecylerView适配器设置动画示例 [示例1-3]下面将在RecylerView的子元素进行滚动时,使用适配器动画.具体的操作步骤如下: (1)创建一个名为R ...

  2. Swift - transform.m34动画示例

    Swift - transform.m34动画示例 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CATransform3DM ...

  3. Android ListView动画特效实现原理及源代码

    Android 动画分三种,当中属性动画为我们最经常使用动画,且能满足项目中开发差点儿所有需求,google官方包支持3.0+.我们能够引用三方包nineoldandroids来失陪到低版本号.本样例 ...

  4. canvas高级动画示例

    canvas高级动画示例 演示地址 https://qzruncode.github.io/example/index.html <!DOCTYPE html> <html lang ...

  5. canvas基础动画示例

    canvas基础动画示例 本文主要用最简单的例子,展示canvas动画效果是如何实现的 动画效果,是一个球绕着一点旋转 const canvas = document.getElementById(' ...

  6. 【补间动画示例】Tweened Animation

    代码中定义动画示例 public class MainActivity extends ListActivity </integer> 常用的Activity转场动画中的补间动画 publ ...

  7. Android ListView动画实现方法

    在Android中listview是最经常使用的控件之中的一个,可是有时候我们会认为千篇一律的listview看起来过于单调,于是就产生了listView动画,listview载入了动画会让用户体验更 ...

  8. 95秀-PullToRefreshListView 示例

        正在加载.暂无数据页面 public class RefreshGuideTool {     private RelativeLayout rl_loading_guide;//整个View ...

  9. [DeviceOne开发]-手势动画示例分享

    一.简介 这是iOS下的效果,android下完全一致.通过do_GestureView组件和do_Animation组件,deviceone能很容易实现复杂的跨平台纯原生动画效果,这个示例就是通过手 ...

随机推荐

  1. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  2. ecshop里Ajax.call()方法定义

    Ajax.call()在哪个文件中定义的? 在加载的js/transport.js文件里面. Ajax.cal()方法就是Transport.run()方法

  3. MLlib-聚类

    聚类 例子 流聚类 例子 聚类 MLlib支持k-means聚类,一种最常用的聚类方法,将数据点聚成指定数据的簇.MLlib实现了一种k-means++的并行变种,叫做kmeansII.MLlib的实 ...

  4. Egret 事件机制

    主要流程: private createGameScene():void { var JimGreen = new Boy(); var HanMeimei = new Girl(); JimGree ...

  5. PYTHON WEATHER

    小玩一下python强大的库文件,调api获取天气情况 #coding:utf-8 import urllib import json content = urllib.urlopen('http:/ ...

  6. 浅谈Java内存泄露

    一.引言 先等等吧……累了

  7. 理解和使用NT驱动程序的执行上下文

    理解Windows NT驱动程序最重要的概念之一就是驱动程序运行时所处的“执行上下文”.理解并小心地应用这个概念可以帮助你构建更快.更高效的驱动程序. NT标准内核模式驱动程序编程的一个重要观念是某个 ...

  8. iconv内容,convmv文件名,unix2dos,dos2unix文件格式转换,od/cut/wc/dd/diff/uniq/nice/du等命令,linux文件名乱码,文件名,文件内容,vim编码设置

    1.enconv文件名编码转换,比如要将一个GBK编码的文件转换成UTF-8编码,操作如下 enconv -L zh_CN -x UTF-8 filename enconv -L GB2312 -x  ...

  9. 【细说Java】Java封箱拆箱的一些问题

    1.概念 首先简单介绍一下概念性的东西: 所谓封箱:就是把基本类型封装成其所对应的包装类型: 而拆箱则恰好相反,是把包装类型转换成其所对应的基本数据类型. 如基本类型int,封箱后的包装类是Integ ...

  10. 【字典树】【贪心】Codeforces 706D Vasiliy's Multiset

    题目链接: http://codeforces.com/contest/706/problem/D 题目大意: 三种操作,1.添加一个数,2.删除一个数,3.查询现有数中与x异或最大值.(可重复) 题 ...