类似微博快速操作弹出界面

如图:由于项目中要用到类似的功能,所以就网上找了找资料,其实这只是个自定义的对话框,将内容显示到底部,

类似微博快速操作弹出界面_第1张图片


自定义控件:QuickOptionDialog.java


package com.juguo.activity;

import com.juguo.cletter.R;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

public class QuickOptionDialog extends Dialog implements
		android.view.View.OnClickListener {

	private ImageView mClose;

	public interface OnQuickOptionformClick {
		void onQuickOptionClick(int id);
	}

	private OnQuickOptionformClick mListener;

	private QuickOptionDialog(Context context, boolean flag,
			OnCancelListener listener) {
		super(context, flag, listener);
	}
	
	@SuppressLint("InflateParams")
	private QuickOptionDialog(Context context, int defStyle) {
		super(context, defStyle);
		View contentView = getLayoutInflater().inflate(
				R.layout.dialog_quick_option, null);
		
		 mClose = (ImageView) contentView.findViewById(R.id.iv_close);

		Animation operatingAnim = AnimationUtils.loadAnimation(getContext(),
				R.anim.quick_option_close);
		LinearInterpolator lin = new LinearInterpolator();
		operatingAnim.setInterpolator(lin);

		mClose.startAnimation(operatingAnim);

		mClose.setOnClickListener(this);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		contentView.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				QuickOptionDialog.this.dismiss();
				return true;
			}
		});
		super.setContentView(contentView);

	}

	public QuickOptionDialog(Context context) {
		this(context, R.style.quick_option_dialog);
	}

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		getWindow().setGravity(Gravity.BOTTOM);

		WindowManager m = getWindow().getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = getWindow().getAttributes();
		p.width = d.getWidth();
		getWindow().setAttributes(p);
	}

	public void setOnQuickOptionformClickListener(OnQuickOptionformClick lis) {
		mListener = lis;
	}

	@Override
	public void onClick(View v) {
		final int id = v.getId();
		switch (id) {
		
		default:
			break;
		}
		if (mListener != null) {
			mListener.onQuickOptionClick(id);
		}
		dismiss();
	}

	private void onClickTweetPub(int id) {
		Bundle bundle = new Bundle();
		int type = -1;
		switch (id) {
		
		default:
			break;
		}
	}

	private void onClickNote() {
		
	}
}



资源文件:




    

        

            

                

                

                    

                        

                        
                    

                    

                    
                
            
        

        

        

        
        

        

        

            

            

            
        
    

    

        
    



调用:


	// 显示快速操作界面
	@OnClick(R.id.iv_call)
	public void showQuickOption() {
		final QuickOptionDialog dialog = new QuickOptionDialog(
				TelePhoneyActivity.this);
		dialog.setCancelable(true);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
	}

通过改变布局,我们可以自己做出很好看的样式来

你可能感兴趣的:(android学习笔记,Dialog,自定义,微博,控件,Android)