亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

自定義PopupWindow動(dòng)畫效果

系統(tǒng) 2120 0
自定義PopupWindow動(dòng)畫效果

    
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);
//		//設(shè)置背景圖片旋轉(zhuǎn)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());//必須設(shè)置background才能消失
		mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
		mPopupWindow.setOutsideTouchable(true);
		
		//自定義動(dòng)畫
//		mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
		//使用系統(tǒng)動(dòng)畫
		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);
	}
}

  


PopupWindow的布局popwindow.xml
注意3個(gè)LinearLayout里必須設(shè)置clickable和background,這樣當(dāng)點(diǎn)擊上去的時(shí)候才會(huì)有點(diǎn)擊效果。
android:clickable="true"
android:background="@drawable/state_btn_pressed"

    
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
 		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"
		>
		<LinearLayout 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"
			>
			<ImageView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:scaleType="fitCenter"
				android:src="@drawable/ic_call"
				>
			</ImageView>
			<TextView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:textColor="#000000"
				android:textSize="18px"
				android:text="電話">
			</TextView>
		</LinearLayout>
		<LinearLayout 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"
			>
			<ImageView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:scaleType="fitCenter"
				android:src="@drawable/ic_home"
				>
			</ImageView>
			<TextView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:textColor="#000"
				android:textSize="18px"
				android:text="空間">
			</TextView>
		</LinearLayout>
		
		<LinearLayout 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"
			>
			<ImageView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:scaleType="fitCenter"
				android:src="@drawable/ic_sms"
				>
			</ImageView>
			<TextView android:layout_width="wrap_content"
				android:layout_height="wrap_content" 
				android:textColor="#000"
				android:textSize="18px"
				android:text="短信"
				>
			</TextView>
		</LinearLayout>
</LinearLayout>

  

state_btn_pressed.xml,點(diǎn)擊的效果:
    
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/bg_btn_pressed"
        android:padding="0dp"/>
</selector>

  


Android 模仿迅雷的 PopupWindow 出現(xiàn)/消失動(dòng)畫
出現(xiàn):
    
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale android:fromXScale="0.6" android:toXScale="1.1"
		android:fromYScale="0.6" android:toYScale="1.1" android:pivotX="50%"
		android:pivotY="50%" android:duration="200" />
	<scale android:fromXScale="1.0" android:toXScale="0.91"
		android:fromYScale="1.0" android:toYScale="0.91" android:pivotX="50%"
		android:pivotY="50%" android:duration="400" android:delay="200" />
	<alpha android:interpolator="@android:anim/linear_interpolator"
		android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400" />
</set>

  

消失:
    
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale android:fromXScale="1.0" android:toXScale="1.25"
		android:fromYScale="1.0" android:toYScale="1.25" android:pivotX="50%"
		android:pivotY="50%" android:duration="200" />
	<scale android:fromXScale="1.0" android:toXScale="0.48"
		android:fromYScale="1.0" android:toYScale="0.48" android:pivotX="50%"
		android:pivotY="50%" android:duration="400" android:delay="200" />
	<alpha android:interpolator="@android:anim/linear_interpolator"
		android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="400" />
</set>

  

最后用下面的 XML 封裝:
    
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="PopupAnimation" parent="android:Animation"
		mce_bogus="1">
		<item name="android:windowEnterAnimation">@anim/anim_dialog_show</item>
		<item name="android:windowExitAnimation">@anim/anim_dialog_hide</item>
	</style>
</resources>

  

自定義PopupWindow動(dòng)畫效果


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 最新日本免费一区二区三区中文 | 精品国产免费观看久久久 | 狠狠色丁香婷婷综合欧美 | 精品一区二区三区中文字幕 | 欧美性久久久久 | 精品国产不卡一区二区三区 | 青草青草久热精品视频在线观看 | 国产在线观看精品 | 香蕉视频日本 | 色久优优 欧美色久优优 | 亚洲伦理久久 | 精品久久久久久中文字幕女 | 精品国产品香蕉在线观看 | 青青热久免费精品视频精品 | 色福利视频 | 国产成+人+亚洲+欧美+日韩 | 99视频在线精品免费观看18 | 荡女人人爱np粗口 | 久久99精品国产自在现线小黄鸭 | 日韩免费一级片 | 久久久久久久久国产 | 亚洲精品国产综合久久一线 | 欧美 亚洲 激情 | 九九香蕉 | 欧美综合图片 | 香蕉色综合 | 91激情视频 | 亚洲精品久久久久福利网站 | 日本特级aⅴ一级毛片 | 久久性生活视频 | 青青青爽视频在线观看 | 国产一级特黄老妇女大片免费 | 操你妹影院 | 色综合久久88色综合天天 | 国产福利在线视频 | 在线观看黄色网 | 国产精品久久久久久久久夜色 | 69香蕉视频 | 日韩欧美在线中文字幕 | 日韩欧美精品一区二区 | 国产成人a∨麻豆精品 |