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. scrapy-redis 实现分布式爬虫

    分布式爬虫 一 介绍 原来scrapy的Scheduler维护的是本机的任务队列(存放Request对象及其回调函数等信息)+本机的去重队列(存放访问过的url地址) 所以实现分布式爬取的关键就是,找 ...

  2. linux使用VNC服务轻松远程安装oracle

    VNC服务在远程服务器上安装oracle,新手安装oracle时总会遇到这样或者那样的问题,下面我就详细解说一下安装过程,其实oracle安装很简单,并不要把他相像的特别复杂. 本环境用:centos ...

  3. service与pod关联

    当我们创建pod时,仅仅是创建了pod,要为其创建rc(ReplicationController),他才会有固定的副本,然后为其创建service,集群内部才能访问该pod,使用 NodePort ...

  4. auth

    谨记:使用的任何框架在网上都会有对应的auth代码,多百度,直接引用插件就好了 tp5 auth 示例:https://blog.csdn.net/strugglm/article/details/7 ...

  5. 05-spring框架—— Spring 事务

    5.1 Spring 的事务管理 事务原本是数据库中的概念,在 Dao 层.但一般情况下,需要将事务提升到业务层,即 Service 层.这样做是为了能够使用事务的特性来管理具体的业务. 在 Spri ...

  6. jq事件操作汇总

    bind()        向匹配元素附加一个或更多事件处理器blur( )        触发.或将函数绑定到指定元素的 blur 事件change()        触发.或将函数绑定到指定元素的 ...

  7. Nginx 的简介

    1. 什么是 nginx :Nginx 是高性能的 HTTP 和反向代理的服务器,处理高并发能力是十分强大的,能经受高负 载的考验,有报告表明能支持高达 50,000 个并发连接数.  2. 正向代理 ...

  8. 一、Flux 是什么?

    React 本身只涉及UI层,如果搭建大型应用,必须搭配一个前端框架.也就是说,你至少要学两样东西,才能基本满足需要:React + 前端框架. Facebook官方使用的是 Flux 框架.本文就介 ...

  9. 发送动态IP到邮件

    # -*-coding:utf8 -*- #!/usr/bin/python import smtplib from email.mime.text import MIMEText # IP impo ...

  10. ionic实现下载文件并打开功能(file-transfer和file-opener2插件)

    作为一款app,下载文件功能,和打开文件功能,在某些场景下还是十分有必要的.使用cordova-plugin-file-transfer和cordova-plugin-file-opener2这两个插 ...