package com.loaderman.customviewdemo;

import android.content.Context;
import android.view.View;
import android.widget.PopupWindow; public class CommonPopupWindow extends PopupWindow {
final PopupController controller; @Override
public int getWidth() {
return controller.mPopupView.getMeasuredWidth();
} @Override
public int getHeight() {
return controller.mPopupView.getMeasuredHeight();
} public interface ViewInterface {
void getChildView(View view, int layoutResId);
} private CommonPopupWindow(Context context) {
controller = new PopupController(context, this);
} @Override
public void dismiss() {
super.dismiss();
controller.setBackGroundLevel(1.0f);
} public static class Builder {
private final PopupController.PopupParams params;
private ViewInterface listener; public Builder(Context context) {
params = new PopupController.PopupParams(context);
} /**
* @param layoutResId 设置PopupWindow 布局ID
* @return Builder
*/
public Builder setView(int layoutResId) {
params.mView = null;
params.layoutResId = layoutResId;
return this;
} /**
* @param view 设置PopupWindow布局
* @return Builder
*/
public Builder setView(View view) {
params.mView = view;
params.layoutResId = 0;
return this;
} /**
* 设置子View
*
* @param listener ViewInterface
* @return Builder
*/
public Builder setViewOnclickListener(ViewInterface listener) {
this.listener = listener;
return this;
} /**
* 设置宽度和高度 如果不设置 默认是wrap_content
*
* @param width 宽
* @return Builder
*/
public Builder setWidthAndHeight(int width, int height) {
params.mWidth = width;
params.mHeight = height;
return this;
} /**
* 设置背景灰色程度
*
* @param level 0.0f-1.0f
* @return Builder
*/
public Builder setBackGroundLevel(float level) {
params.isShowBg = true;
params.bg_level = level;
return this;
} /**
* 是否可点击Outside消失
*
* @param touchable 是否可点击
* @return Builder
*/
public Builder setOutsideTouchable(boolean touchable) {
params.isTouchable = touchable;
return this;
} /**
* 设置动画
*
* @return Builder
*/
public Builder setAnimationStyle(int animationStyle) {
params.isShowAnim = true;
params.animationStyle = animationStyle;
return this;
} public CommonPopupWindow create() {
final CommonPopupWindow popupWindow = new CommonPopupWindow(params.mContext);
params.apply(popupWindow.controller);
if (listener != null && params.layoutResId != 0) {
listener.getChildView(popupWindow.controller.mPopupView, params.layoutResId);
}
CommonUtil.measureWidthAndHeight(popupWindow.controller.mPopupView);
return popupWindow;
}
}
}
package com.loaderman.customviewdemo;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.PopupWindow; class PopupController {
private int layoutResId;//布局id
private Context context;
private PopupWindow popupWindow;
View mPopupView;//弹窗布局View
private View mView;
private Window mWindow; PopupController(Context context, PopupWindow popupWindow) {
this.context = context;
this.popupWindow = popupWindow;
} public void setView(int layoutResId) {
mView = null;
this.layoutResId = layoutResId;
installContent();
} public void setView(View view) {
mView = view;
this.layoutResId = 0;
installContent();
} private void installContent() {
if (layoutResId != 0) {
mPopupView = LayoutInflater.from(context).inflate(layoutResId, null);
} else if (mView != null) {
mPopupView = mView;
}
popupWindow.setContentView(mPopupView);
} /**
* 设置宽度
*
* @param width 宽
* @param height 高
*/
private void setWidthAndHeight(int width, int height) {
if (width == 0 || height == 0) {
//如果没设置宽高,默认是WRAP_CONTENT
popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
} else {
popupWindow.setWidth(width);
popupWindow.setHeight(height);
}
} /**
* 设置背景灰色程度
*
* @param level 0.0f-1.0f
*/
void setBackGroundLevel(float level) {
mWindow = ((Activity) context).getWindow();
WindowManager.LayoutParams params = mWindow.getAttributes();
params.alpha = level;
mWindow.setAttributes(params);
} /**
* 设置动画
*/
private void setAnimationStyle(int animationStyle) {
popupWindow.setAnimationStyle(animationStyle);
} /**
* 设置Outside是否可点击
*
* @param touchable 是否可点击
*/
private void setOutsideTouchable(boolean touchable) {
popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));//设置透明背景
popupWindow.setOutsideTouchable(touchable);//设置outside可点击
popupWindow.setFocusable(touchable);
} static class PopupParams {
public int layoutResId;//布局id
public Context mContext;
public int mWidth, mHeight;//弹窗的宽和高
public boolean isShowBg, isShowAnim;
public float bg_level;//屏幕背景灰色程度
public int animationStyle;//动画Id
public View mView;
public boolean isTouchable = true; public PopupParams(Context mContext) {
this.mContext = mContext;
} public void apply(PopupController controller) {
if (mView != null) {
controller.setView(mView);
} else if (layoutResId != 0) {
controller.setView(layoutResId);
} else {
throw new IllegalArgumentException("PopupView's contentView is null");
}
controller.setWidthAndHeight(mWidth, mHeight);
controller.setOutsideTouchable(isTouchable);//设置outside可点击
if (isShowBg) {
//设置背景
controller.setBackGroundLevel(bg_level);
}
if (isShowAnim) {
controller.setAnimationStyle(animationStyle);
}
}
}
}
package com.loaderman.customviewdemo;

import android.view.View;

public class CommonUtil {
/**
* 测量View的宽高
*
* @param view View
*/
public static void measureWidthAndHeight(View view) {
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(w, h);
}
}
package com.loaderman.customviewdemo;

import android.content.Context;
public class DpUtil {
/**
* dp转换成px
*
* @param context Context
* @param dp dp
* @return px值
*/
public static float dp2px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return dp * scale + 0.5f;
} }
package com.loaderman.customviewdemo;

import android.view.View;
public interface MyOnclickListener {
void onItemClick(View view, int position);
}
package com.loaderman.customviewdemo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List; public class PopupAdapter extends RecyclerView.Adapter<PopupAdapter.MyViewHolder> {
private Context mContext;
private List<String> list;
private MyOnclickListener myItemClickListener; public PopupAdapter(Context mContext) {
this.mContext = mContext;
} public void setOnItemClickListener(MyOnclickListener listener) {
this.myItemClickListener = listener;
} @Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.popup_item, parent, false);
return new MyViewHolder(view);
} @Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
holder.choice_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (myItemClickListener != null) {
myItemClickListener.onItemClick(v, position);
}
}
});
} @Override
public int getItemCount() {
return 15;
} public class MyViewHolder extends RecyclerView.ViewHolder {
TextView choice_text; public MyViewHolder(final View itemView) {
super(itemView);
choice_text = (TextView) itemView.findViewById(R.id.choice_text);
}
}
}
package com.loaderman.customviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends AppCompatActivity implements CommonPopupWindow.ViewInterface {
private CommonPopupWindow popupWindow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
//向下弹出
public void showDownPop(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_down)
.setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.setAnimationStyle(R.style.AnimDown)
.setViewOnclickListener(this)
.setOutsideTouchable(true)
.create();
popupWindow.showAsDropDown(view);
//得到button的左上角坐标
// int[] positions = new int[2];
// view.getLocationOnScreen(positions);
// popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, 0, positions[1] + view.getHeight());
} //向右弹出
public void showRightPop(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_left_or_right)
.setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.setAnimationStyle(R.style.AnimHorizontal)
.setViewOnclickListener(this)
.create();
popupWindow.showAsDropDown(view, view.getWidth(), -view.getHeight());
//得到button的左上角坐标
// int[] positions = new int[2];
// view.getLocationOnScreen(positions);
// popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, positions[0] + view.getWidth(), positions[1]);
} //向左弹出
public void showLeftPop(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_left_or_right)
.setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.setAnimationStyle(R.style.AnimRight)
.setViewOnclickListener(this)
.create();
popupWindow.showAsDropDown(view, -popupWindow.getWidth(), -view.getHeight());
//得到button的左上角坐标
// int[] positions = new int[2];
// view.getLocationOnScreen(positions);
// popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, positions[0] - popupWindow.getWidth(), positions[1]);
} //全屏弹出
public void showAll(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
View upView = LayoutInflater.from(this).inflate(R.layout.popup_up, null);
//测量View的宽高
CommonUtil.measureWidthAndHeight(upView);
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_up)
.setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, upView.getMeasuredHeight())
.setBackGroundLevel(0.5f)//取值范围0.0f-1.0f 值越小越暗
.setAnimationStyle(R.style.AnimUp)
.setViewOnclickListener(this)
.create();
popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
} //向上弹出
public void showUpPop(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_left_or_right)
.setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.setViewOnclickListener(this)
.create();
popupWindow.showAsDropDown(view, 0, -(popupWindow.getHeight() + view.getMeasuredHeight())); //得到button的左上角坐标
// int[] positions = new int[2];
// view.getLocationOnScreen(positions);
// popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, positions[0], positions[1] - popupWindow.getHeight());
} public void showReminder(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.query_info)
.setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.create();
popupWindow.showAsDropDown(view, (int) (-popupWindow.getWidth() + DpUtil.dp2px(this, 20)), -(popupWindow.getHeight() + view.getMeasuredHeight()));
} @Override
public void getChildView(View view, int layoutResId) {
//获得PopupWindow布局里的View
switch (layoutResId) {
case R.layout.popup_down:
RecyclerView recycle_view = (RecyclerView) view.findViewById(R.id.recycle_view);
recycle_view.setLayoutManager(new GridLayoutManager(this, 3));
PopupAdapter mAdapter = new PopupAdapter(this);
recycle_view.setAdapter(mAdapter);
mAdapter.setOnItemClickListener(new MyOnclickListener() {
@Override
public void onItemClick(View view, int position) {
if (popupWindow != null) {
popupWindow.dismiss();
}
}
});
break;
case R.layout.popup_up:
Button btn_take_photo = (Button) view.findViewById(R.id.btn_take_photo);
Button btn_select_photo = (Button) view.findViewById(R.id.btn_select_photo);
Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
btn_take_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "拍照", Toast.LENGTH_SHORT).show();
if (popupWindow != null) {
popupWindow.dismiss();
}
}
});
btn_select_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "相册选取", Toast.LENGTH_SHORT).show();
if (popupWindow != null) {
popupWindow.dismiss();
}
}
});
btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (popupWindow != null) {
popupWindow.dismiss();
}
}
});
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (popupWindow != null) {
popupWindow.dismiss();
}
return true;
}
});
break;
case R.layout.popup_left_or_right:
TextView tv_like = (TextView) view.findViewById(R.id.tv_like);
TextView tv_hate = (TextView) view.findViewById(R.id.tv_hate);
tv_like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "赞一个", Toast.LENGTH_SHORT).show();
popupWindow.dismiss();
}
});
tv_hate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "踩一下", Toast.LENGTH_SHORT).show();
popupWindow.dismiss();
}
});
break;
}
}
}

anim文件下创建

push_bottom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 上下滑入式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate
android:duration="200"
android:fromYDelta="50%p"
android:toYDelta="0"/>
</set>

push_bottom_out.xml

<?xml version="1.0" encoding="utf-8"?><!-- 上下滑入式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromYDelta="0"
android:toYDelta="50%p" />
</set>

push_scale_in.xml

<?xml version="1.0" encoding="utf-8"?><!-- 左上角扩大-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"> <scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>

push_scale_out.xml

<?xml version="1.0" encoding="utf-8"?><!-- 左上角扩大-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"> <scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="0.001" />
</set>

push_scale__left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="0.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />

push_scale__left_out.xml

<?xml version="1.0" encoding="utf-8"?>

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="0.0"
android:toYScale="1.0" />

push_scale__right_in.xml

<?xml version="1.0" encoding="utf-8"?><!-- 左上角扩大-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"> <scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="0.0"
android:fromYScale="1.0"
android:pivotX="100%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>

push_scale__right_out.xml

<?xml version="1.0" encoding="utf-8"?><!-- 左上角扩大-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"> <scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="100%"
android:toXScale="0.0"
android:toYScale="1.0" />
</set>

color文件下创建

popup_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#6fb30d" android:state_pressed="true" />
<item android:color="#FF000000" />
</selector>

drawable文件下

popup_grey_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="6dp" />
<solid android:color="@color/black_deep" />
</shape>

popup_item_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 android:shape="rectangle">
<corners android:radius="6dp" />
<padding android:bottom="10dp" android:left="20dp" android:right="20dp" android:top="10dp" />
<solid android:color="@color/white" />
<stroke android:width="1dp" android:color="@color/green_deep_color" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="6dp" />
<solid android:color="@color/white" />
<padding android:bottom="10dp" android:left="20dp" android:right="20dp" android:top="10dp" />
<stroke android:width="1dp" android:color="@color/black_deep" />
</shape>
</item>
</selector>

layout文件下创建

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:onClick="showDownPop"
android:text="向下弹出"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:onClick="showRightPop"
android:text="向右弹出"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="200dp"
android:onClick="showLeftPop"
android:text="向左弹出"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="showAll"
android:text="全屏弹出(带阴影)"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:onClick="showUpPop"
android:text="向上弹出"/> <ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="40dp"
android:layout_marginRight="40dp"
android:onClick="showReminder"
android:src="@mipmap/query_icon_normal"/> </RelativeLayout>

popup_down.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="#b0000000"
android:orientation="vertical"> <android.support.v7.widget.RecyclerView
android:id="@+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:overScrollMode="never" /> </LinearLayout>

popup_item.xml

<?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="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/choice_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/popup_item_bg"
android:text="王者XXOO"
android:textColor="@color/popup_color" /> </RelativeLayout>

popup_left_or_right.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> <LinearLayout
android:layout_width="161dp"
android:layout_height="40dp"
android:background="@drawable/popup_grey_bg"
android:orientation="horizontal"> <TextView
android:id="@+id/tv_like"
android:layout_width="80dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="赞一个"
android:textColor="@color/white"
android:textSize="16dp" /> <View
android:layout_width="1dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:background="@color/bbbbbb_2.3" /> <TextView
android:id="@+id/tv_hate"
android:layout_width="80dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="踩一下"
android:textColor="@color/white"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>

popup_up.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pop_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="vertical"> <Button
android:id="@+id/btn_take_photo"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="拍照"
android:textColor="#282828"
android:textSize="16sp" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_holo_light" /> <Button
android:id="@+id/btn_select_photo"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="相册选取"
android:textColor="#282828"
android:textSize="16sp" /> <View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@color/gray_holo_light" /> <Button
android:id="@+id/btn_cancel"
style="?android:attr/borderlessButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="取消"
android:textColor="#282828"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>

query_info.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="#00000000"
android:orientation="vertical"> <TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/mark_pic_normal"
android:gravity="center_vertical"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="20dp"
android:text="你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好你好好你好好好" /> </LinearLayout>

color.xml

    <color name="holo_blue_light">#ff33b5e5</color>
<color name="white">#ffffff</color>
<color name="black_deep">#FF000000</color>
<color name="bbbbbb_2.3">#bbbbbb</color>
<color name="green_deep_color">#6fb30d</color>
<item name="gray_holo_light" type="color">#ffd0d0d0</item>

styles.xml

 <style name="AnimDown" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_scale_in</item>
<item name="android:windowExitAnimation">@anim/push_scale_out</item>
</style>
<style name="AnimUp" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
<item name="android:windowExitAnimation">@anim/push_bottom_out</item>
</style> <style name="AnimHorizontal" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_scale_left_in</item>
<item name="android:windowExitAnimation">@anim/push_scale_left_out</item>
</style> <style name="AnimRight" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_scale_right_in</item>
<item name="android:windowExitAnimation">@anim/push_scale_right_out</item>
</style>

效果图:

自定义PopupWindow实现常用效果的更多相关文章

  1. 自定义PopupWindow

    PopupWindow,一个弹出窗口控件,可以用来显示任意View,而且会浮动在当前activity的顶部 自定义PopupWindow. 1.extends PopupWindow 2.构造方法中可 ...

  2. 自定义PopupWindow弹出框(带有动画)

    使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { pub ...

  3. Android 自定义View修炼-【2014年最后的分享啦】Android实现自定义刮刮卡效果View

    一.简介: 今天是2014年最后一天啦,首先在这里,我祝福大家在新的2015年都一个个的新健康,新收入,新顺利,新如意!!! 上一偏,我介绍了用Xfermode实现自定义圆角和椭圆图片view的博文& ...

  4. Xcode自定义Eclipse中常用的快捷键

    转载自http://joeyio.com/2013/07/22/xcode_key_binding_like_eclipse/ Xcode自定义Eclipse中常用的快捷键 22 July 2013 ...

  5. jS事件之网站常用效果汇总

    下拉菜单 <!--简单的设置了样式,方便起见,将style和script写到同一个文档,着重练习事件基础--> <!DOCTYPE html> <html> < ...

  6. android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

    shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看  api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...

  7. Qt实现自定义按钮的三态效果

    好久之前做的一个小软件,好长时间没动过了,在不记录下有些细节可能都忘了,这里整理下部分功能的实现. 按钮的三态,指的是普通态.鼠标的停留态.点击态,三态是界面交互非常基本的一项功能,Qt中如果使用的是 ...

  8. Android 自定义View跑马灯效果(一)

    今天通过书籍重新复习了一遍自定义VIew,为了加强自己的学习,我把它写在博客里面,有兴趣的可以看一下,相互学习共同进步: 通过自定义一个跑马灯效果,来诠释一下简单的效果: 一.创建一个类继承View, ...

  9. Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果

    一:如何自定义TextView实现滚动效果 继承TextView基类 重写构造方法 修改isFocused()方法,获取焦点. /* * Copyright (C) 2015 The Android ...

随机推荐

  1. 【异常】~/.bash_profile:source:44: no such file or directory: /usr/local/Cellar/nvm/0.34.0/nvm.sh

    1 异常信息 /Users/zhangjin/.bash_profile:source:: no such file or directory: /usr/local/Cellar/nvm//nvm. ...

  2. SSD源码解读——网络搭建

    之前,对SSD的论文进行了解读,可以回顾之前的博客:https://www.cnblogs.com/dengshunge/p/11665929.html. 为了加深对SSD的理解,因此对SSD的源码进 ...

  3. logging:不喜欢写日志可不好哦

    logging模块简介 logging模块是python内置的标准模块,主要用于输出程序的运行日志. 可以设置输出日志的等级,日志保存路径,日志文件回滚等等. logging模块的基本使用 impor ...

  4. IIS 程序池优化配置方案

    内容目录 IIS 程序池优化配置方案IIS高并发配置一.IIS站点绑定程序池设置二.支持万级并发请求 IIS 程序池优化配置方案 最近由于系统的客户越来越多,有客户反映访问速度变慢,尤其是api的请求 ...

  5. init container

    init container与应用容器在本质上是一样的, 但它们是仅运行一次就结束的任务, 并且必须在成功执行完成后, 系统才能继续执行下一个容器, 可以用在例如应用容器启动前做一些初始化工作,当in ...

  6. PAT Basic 1014 福尔摩斯的约会 (20 分)

    大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...

  7. 小程序UI设计之-介绍篇

    工具截图 此工具通过可视化操作进行布局,依据iphone6尺寸设置画布,可以自动生成rpx和百分比的wxss.后续还会增加js代码自动生成.工具中组件按照微信小程序开发规范进行了缺省设置,margin ...

  8. radio赋值法

    一般都会使用attr来使选中: $("#DIV的ID input[name='radio的name'][value="'+动态传的radio的value值+'"]&quo ...

  9. SpringBoot 在IDEA中实现热部署(实用版)(引入)

    SpringBoot 在IDEA中实现热部署(实用版) 引用:https://www.jianshu.com/p/f658fed35786 好的热部署让开发调试事半功倍,这样的“神技能”怎么能错过呢, ...

  10. Springboot项目全局异常统一处理

    转自https://blog.csdn.net/hao_kkkkk/article/details/80538955 最近在做项目时需要对异常进行全局统一处理,主要是一些分类入库以及记录日志等,因为项 ...