PopupWindow实现微信右上角菜单

蛋疼的各种仿照效果,UI一定要伺候好,不然一言不合就给你来一个很NB的效果


上代码!

1.资源图片

PopupWindow实现微信右上角菜单_第1张图片        


2.popupWindow入场动画


3.自定义popupWindow


package com.amistrong.beautifulstar.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.amistrong.beautifulstar.chat.activity.GroupChatActivity;
import com.amistrong.beautifulstar.R;
import com.amistrong.beautifulstar.find.ui.activity.friend.MyFriendActivity;
import com.amistrong.beautifulstar.utils.scancodetool.decoding.Intents;

public class MorePopWindow extends PopupWindow {
    private View conentView;
    private String userId;
    public MorePopWindow(final Activity context) {
        final LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.popup_window_chat, null);
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        this.setContentView(conentView);
        this.setWidth(LayoutParams.WRAP_CONTENT);
        this.setHeight(LayoutParams.WRAP_CONTENT);
        //设置点击隐藏的属性
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        this.update();
        ColorDrawable dw = new ColorDrawable(0000000000);
        this.setBackgroundDrawable(dw);
        this.setAnimationStyle(R.style.AnimationPreview);
        RelativeLayout getChat = (RelativeLayout) conentView.findViewById(R.id.getChat);
        RelativeLayout getGroup = (RelativeLayout) conentView.findViewById(R.id.getGroup);
        getChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击弹出按钮的操作
                Intent intent=new Intent(context, MyFriendActivity.class);
                context.startActivity(intent);
                MorePopWindow.this.dismiss();
            }
        });
        getGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GroupChatActivity.class);
                context.startActivity(intent);
                MorePopWindow.this.dismiss();
            }
        });
    }

    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 10);
        } else {
            this.dismiss();
        }
    }
}


4.xml文件


xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:id="@+id/llPop"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:orientation="vertical">
            android:descendantFocusability="blocksDescendants"
        android:id="@+id/llChatFragmentChat"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/rlChatFragmentTitle"
        android:layout_marginRight="5dp"
        android:background="@mipmap/chat_96"
        android:orientation="vertical">

                    android:layout_marginTop="10dp"
            android:id="@+id/getChat"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

                            android:id="@+id/ivChatOne"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:src="@mipmap/chat_98" />

                            android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/ivChatOne"
                android:text="发起聊天"
                android:textColor="@android:color/white"
                android:textSize="@dimen/text_content_15" />
        

                    android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="5dp"
            android:background="@color/view_background" />

                    android:id="@+id/getGroup"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

                            android:id="@+id/ivChatTwo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:src="@mipmap/chat_99" />

                            android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/ivChatTwo"
                android:text="发起群聊"
                android:textColor="@android:color/white"
                android:textSize="@dimen/text_content_15" />
        
    


结束


你可能感兴趣的:(android控件)