魔灵觉醒:自定义PopupWindow动画效果
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 20:37:02
自定义PopupWindow动画效果
- 博客分类:
- android动画&效果
Java代码
- public class RollActivity extends Activity {
- private View view;
- private Button btn;
- private PopupWindow mPopupWindow;
- private View[] btns;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // LinearLayout layout=(LinearLayout) view.findViewById(R.id.layout_main);
- // //设置背景图片旋转180
- // Bitmap mBitmap=setRotate(R.drawable.bg_kuang);
- // BitmapDrawable drawable=new BitmapDrawable(mBitmap);
- // layout.setBackgroundDrawable(drawable);
- btn=(Button) this.findViewById(R.id.btn);
- btn.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- showPopupWindow(btn);
- }
- });
- initPopupWindow(R.layout.popwindow);
- }
- private void initPopupWindow(int resId){
- LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
- view = mLayoutInflater.inflate(resId, null);
- mPopupWindow = new PopupWindow(view, 400,LayoutParams.WRAP_CONTENT);
- // mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//必须设置background才能消失
- mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
- mPopupWindow.setOutsideTouchable(true);
- //自定义动画
- // mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
- //使用系统动画
- mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
- mPopupWindow.update();
- mPopupWindow.setTouchable(true);
- mPopupWindow.setFocusable(true);
- btns=new View[3];
- btns[0]=view.findViewById(R.id.btn_0);
- btns[1]=view.findViewById(R.id.btn_1);
- btns[2]=view.findViewById(R.id.btn_2);
- btns[0].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- btns[1].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- btns[2].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- }
- private void showPopupWindow(View view) {
- if(!mPopupWindow.isShowing()){
- // mPopupWindow.showAsDropDown(view,0,0);
- mPopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
- }
- }
- public Bitmap setRotate(int resId) {
- Matrix mFgMatrix = new Matrix();
- Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);
- mFgMatrix.setRotate(180f);
- return mFgBitmap=Bitmap.createBitmap(mFgBitmap, 0, 0,
- mFgBitmap.getWidth(), mFgBitmap.getHeight(), mFgMatrix, true);
- }
- }
public class RollActivity extends Activity {private View view;private Button btn;private PopupWindow mPopupWindow;private View[] btns; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//LinearLayout layout=(LinearLayout) view.findViewById(R.id.layout_main);////设置背景图片旋转180//Bitmap mBitmap=setRotate(R.drawable.bg_kuang);//BitmapDrawable drawable=new BitmapDrawable(mBitmap);//layout.setBackgroundDrawable(drawable); btn=(Button) this.findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubshowPopupWindow(btn);} }); initPopupWindow(R.layout.popwindow); } private void initPopupWindow(int resId){LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); view = mLayoutInflater.inflate(resId, null); mPopupWindow = new PopupWindow(view, 400,LayoutParams.WRAP_CONTENT);//mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//必须设置background才能消失mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));mPopupWindow.setOutsideTouchable(true);//自定义动画//mPopupWindow.setAnimationStyle(R.style.PopupAnimation);//使用系统动画mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);mPopupWindow.update();mPopupWindow.setTouchable(true);mPopupWindow.setFocusable(true);btns=new View[3];btns[0]=view.findViewById(R.id.btn_0);btns[1]=view.findViewById(R.id.btn_1);btns[2]=view.findViewById(R.id.btn_2);btns[0].setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//doSomething}});btns[1].setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//doSomething}});btns[2].setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//doSomething}});}private void showPopupWindow(View view) {if(!mPopupWindow.isShowing()){//mPopupWindow.showAsDropDown(view,0,0);mPopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);}}public Bitmap setRotate(int resId) {Matrix mFgMatrix = new Matrix();Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);mFgMatrix.setRotate(180f);return mFgBitmap=Bitmap.createBitmap(mFgBitmap, 0, 0, mFgBitmap.getWidth(), mFgBitmap.getHeight(), mFgMatrix, true);}}
PopupWindow的布局popwindow.xml
注意3个LinearLayout里必须设置clickable和background,这样当点击上去的时候才会有点击效果。
android:clickable="true"
android:background="@drawable/state_btn_pressed"
Xml代码
- version="1.0" encoding="utf-8"?>
-
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:id="@+id/layout_main"
- >
-
android:layout_width="fill_parent" - android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_0"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_call"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:textColor="#000000"
- android:textSize="18px"
- android:text="电话">
-
android:layout_width="fill_parent" - android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_1"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_home"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:textColor="#000"
- android:textSize="18px"
- android:text="空间">
-
android:layout_width="fill_parent" - android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_2"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_sms"
- >
-
android:layout_width="wrap_content" - android:layout_height="wrap_content"
- android:textColor="#000"
- android:textSize="18px"
- android:text="短信"
- >
state_btn_pressed.xml,点击的效果:
Xml代码
- version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"> -
- android:state_pressed="true"
- android:drawable="@drawable/bg_btn_pressed"
- android:padding="0dp"/>
自定义PopupWindow动画效果
利用自定义动画强调效果做单选
PopupWindow
自定义动画视频
可以自定义打字效果的个性留言板
Android 动画效果
制作PowerPoint动画效果
Photoshop制作涟漪动画效果
Photoshop制作滴墨成花动画效果
打造真人动画效果片头
【引用】制作下雨动画效果
做多张图片动画效果教程
U5制作翻页动画效果
Animation动画效果的实现
引用 怎样添加自定义模块和在自定义模块中做动画的超级链接
Android动画效果 translate、scale、alpha、rotate 切换Activity动画
flash动画制作实例:动感模糊效果
Photoshop打造小溪潺潺流水的动画效果
Flash制作切片式图片效果动画
ps制作卷轴展开动画效果
羽化遮罩效果flash动画
最新整理开场动画效果代码
photoshop制作飘动的头发动画效果
经络图(动画效果比较好)