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. FMDB警告Warning: there is at least one open result set around after performing的问题

    FMDB操作sqlite的时候总是报警告Warning: there is at least one open result set around after performing,后来发现是执行查询 ...

  2. call和apply

    在js中经常会看到call和apply,他们实际上就是用于改变this的上下文 经典例子 function pet(words) { this.words=words; this.speak=func ...

  3. [转]JS继承的5种实现方式

    参考链接: http://yahaitt.iteye.com/blog/250338 虽说书上都讲过继承的方式方法,但这些东西每看一遍都多少有点新收获,所以单独拿出来放着. 1. 对象冒充 funct ...

  4. Delphi Keycode

    Keycode表 字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L ...

  5. linux c数据库备份第四版

    该版本算是比较成熟的啦,欢迎大伙拿来试用!!!1.新增数据库连接和备份时间配置文件conf2.新增日志文件,程序运行的一些异常会记录在log文件下 后续的工作:1.将代码切割为多个文件,分类存放代码2 ...

  6. DNS解析原理

    1.在浏览器中输入www.qq.com域名,操作系统会先检查自己本地的hosts文件是否有这个网址映射关系,如果有,就先调用这个IP地址映射,完成域名解析. 2.如果hosts里没有这个域名的映射,则 ...

  7. 所有语言的Awesome

    Awesome Awesomeness A curated list of amazingly awesome awesomeness. Also available on: Awesome-Awes ...

  8. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  9. Spark SQL Table Join(Python)

    示例   Spark SQL注册“临时表”执行“Join”(Inner Join.Left Outer Join.Right Outer Join.Full Outer Join)   代码   fr ...

  10. HDOJ(HDU) 1985 Conversions(汇率转换)

    Problem Description Conversion between the metric and English measurement systems is relatively simp ...