androiddialog動畫
㈠ 安卓開發中:把Activity設置為dialog模式後,無法控制消失動畫的問題!
不知道你是怎麼設置的消失動畫,即使設置了Dialog的Theme 他本質上還是Activity的,應該設置Activity切換動畫overridePendingTransition(R.anim.alpha_appear,R.anim.alpha_disappear);
㈡ 如何自定義Android Dialog的樣式
Android 中自定義Dialog的樣式,主要是通過自定義的xml,然後載入到dialog的背景中,如下步驟:
1、自定義Dialog
java">finalDialogdialog=newDialog(this,R.style.Theme_dialog);
2、窗口布局
ViewcontentView=LayoutInflater.from(this).inflate(R.layout.select_list_dialog,null);
3、把設定好的窗口布局放到dialog中
dialog.setContentView(contentView);
4、設定點擊窗口空白處取消會話
dialog.setCanceledOnTouchOutside(true);
5、具體的操作
ListViewmsgView=(ListView)contentView.findViewById(R.id.listview_flow_list);
6、展示窗口
dialog.show();
例:
finalDialogdialog=newDialog(this,R.style.Theme_dialog);
ViewcontentView=LayoutInflater.from(this).inflate(R.layout.select_list_dialog,null);
dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(true);
ListViewmsgView=(ListView)contentView.findViewById(R.id.listview_flow_list);
TextViewtitleText=(TextView)contentView.findViewById(R.id.title);
titleText.setText("請選擇銀行卡");
=(this,mBankcardList);
msgView.setAdapter(adapter);
msgView.setOnItemClickListener(newOnItemClickListener(){
@Override
publicvoidonItemClick(AdapterViewparent,Viewview,intposition,longid){
//Toast.makeText(RechargeFlowToMobileActivity.this,
//position+"",0).show();
mSelectCard=mBankcardList.get(position);
Stringarea=mSelectCard.getBank_card();
mCardNumberText.setText(area);
dialog.dismiss();
}
});
ButtoncloseBtn=(Button)contentView.findViewById(R.id.close);
closeBtn.setClickable(true);
closeBtn.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
dialog.dismiss();
}
});
dialog.show();
以上就是在Android開發自定義dialog樣式的方法和步驟,android很多的控制項都提供了介面或者方法進行樣式的定義和修改。
㈢ Android Dialog動畫效果無效
Window w= dialog.getWindow();
w.setWindowAnimations(R.style.PopupAnimation);
dialog.show();
你的代碼完全沒有問題,莫非和API版本有關?我在API 14上一切正常。
㈣ Android Dialog如何顯示在空間的下面
Android中Alertdialog是沒有直接顯示在指定控制項下的API的,你可以使用PopupWindow來實現顯示在指定控制項下面的需求。PopupWindow不僅能顯示在指定位置,還可以指定顯示和消失的動畫,不必限定死必須用哪個控制項,只需要實現需求即可。
PopupWindow 是一個可以顯示在當前 Activity 之上的浮動容器,PopupWindow 彈出的位置是能夠改變的,按照有無偏移量,可以分為無偏移和有偏移兩種;按照參照對象的不同又可以分為兩種:相對某個控制項(Anchor 錨點)的位置和在父容器內部的相對位置。
LayoutInflatermLayoutInflater=(LayoutInflater)context.getSystemService(LAYOUT_INFLATER_SERVICE);
ViewcontentView=mLayoutInflater.inflate(R.layout.pop,null)
//R.layout.pop為PopupWindow的布局文件
PopupWindowpop=newPopupWindow(contentView,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
pop.setBackgroundDrawable(newBitmapDrawable());
//指定PopupWindow的背景
pop.setFocusable(true);
//指定PopupWindow顯示在你指定的view下
pop.showAsDropDown(your_view);
㈤ 開發者選項窗口動畫和過渡動畫區別
窗口動畫和過渡動畫是指在窗口(activity或dialog)切換時的顯示動畫,窗口動畫的范圍相對較廣,包括activity和dialog,而過渡動畫只包括activity。
? 第一種方法是調用overridePendingTransition的方法,記得要在startActivity之前調用,還可以用startActivity(Intent, Bundle)設置Bundle來實現,這種可以跨Context,而overridePendingTransition只能在當前app內實現,具體做法是ActivityOptions.makeCustomAnimation(context, enterResId, exitResId).toBundle(),這種方法要求系統是4.1以後的。這兩種方法實現的都是過渡動畫。
? 前面這些方法都只能做activity的動畫,要做dialog的動畫,就必須用窗口動畫。方法是設置style,然後dialog.getWindow().setWindowAnimations(R.style.MyStyle)或者dialog.getWindow().getAttributes().windowAnimations = R.style.MyStyle;這樣就可以在彈出dialog的時候播放動畫了。窗口動畫也可以作用在activity上,style的設置一樣,代碼也差不多,直接在activity內就可以調用getWindow這條方法。style還有另外一種做法:
? 這種設置的是過渡動畫,只對activity有用,對dialog沒用。(除了用getWindow來設置動畫資源外,還可以在你的Theme里添加一個item,item的name是android:windowAnimationStyle,然後指定上面的一種style)。
? 從原理上看,窗口動畫和過渡動畫其實就是系統在切換窗口時讀取相應的動畫資源,上面的所有做法本質上就是在替換那些資源。開發者需要處理的是如何選擇,是窗口動畫還是過渡動畫。如果是dialog,只有窗口動畫可選,也只能通過style來完成。如果是activity,就兩種動畫都可以,但大多情況下還是用過渡動畫,因為通過像overridePendingTransition這些api可以很簡單的實現,而如果想把動畫應用到整個Activity,用style就更方便,至於用上面哪種style,其實沒什麼影響。
? 在實際的開發中,其實並不提倡用上面這些方法,因為手機的設置可以關閉這兩種動畫(在開發者選項那裡),你沒法保證app一定能顯示動畫。對於activity動畫來說,可以在新的activity初始化結束後啟動常規的動畫,但這種方法要求你必須等到窗口的相關view初始化結束,但什麼時候結束是無法預測的,這和手機性能有關,所以你可以設置定時器來播放,而對於dialog就沒有其他解決的方法了。
㈥ android 使用activity 當dialog彈出框 ,layout出現左右兩邊有間距
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
getWindow().setAttributes(lp);
㈦ 怎麼用Android實現ActionSheet效果
需要在項目中使用到類似iOS ActionSheet的動畫效果,在查閱了一些資料後,順利實現了,在這里把方法分享給大家。
1、首先在res/anim文件夾下創建slide_up.xml和slide_down.xml(文件名隨意),代碼如下:
3.最後,在dialog彈出之前,使用剛剛實現的動畫效果:
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
㈧ Android操作系統中默認的loading動畫怎麼調用
progressdialog先添加要載入xml面
始隱藏其組件
顯示progressdialog
延遲段間再顯示其組件隱藏progressdialog
// 圖片數量
private int count =8;
//圖片ID數組
private int[] ids={R.drawable.r1,R.drawable.r2,R.drawable.r3,R.drawable.r4,
R.drawable.r5,R.drawable.r6,R.drawable.r7,R.drawable.r8};
private Handler handler;
private ImageView img_loading;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
img_loading = (ImageView) this.findViewById(R.id.img_loading);
handler = new Handler(){
public void handleMessage(Message msg)
{
/**
* 更改ImageView圖片
*/
img_loading.setImageDrawable(getDrawable(msg.what));
}
};
play();
}
/**
* 獲取圖片象
* @param id
* @return
*/
private Drawable getDrawable(int id)
{
return this.getResources().getDrawable(ids[id]);
}
/**
* 播放畫
*/
private void play()
{
new Thread(){
@SuppressWarnings("static-access")
@Override
public void run()
{
while(true)
{
for (int i = 0; i < count; i++)
{
handler.sendEmptyMessage(i);
try
{
this.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}.start();
}
㈨ 關於android中Dialog顯示動畫的問題,求教
可以用popupWindow來實現 popupWindow.setFocusable(true); popupWindow.setAnimationStyle(android.R.style.Animation_Dialog); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); 加上這幾句話就可以了 ,跟dialog有相同的效果 Dialog也可以實現,但是我沒有研究,你可以試試,有了答案告訴一下,
㈩ android 旋轉 dialog會自動旋轉嗎
android源代碼之Rotate旋轉動畫 標簽為旋轉節點 Tween一共為我們提供了3種動畫渲染模式。 android:interpolator="@android:anim/accelerate_interpolator" 設置動畫渲染器為加速動畫(動畫播放中越來越快) android:interpolator="@android:anim/decelerate_interpolator" 設置動畫渲染器為減速動畫(動畫播放中越來越慢) android:interpolator="@android:anim/accelerate_decelerate_interpolator" 設置動畫渲染器為先加速在減速(開始速度最快 逐漸減慢) 如果不寫的話 默認為勻速運動 android:fromDegrees="+360"設置動畫開始的角度 android:toDegrees="0"設置動畫結束的角度 這個動畫布局設置動畫將向左做360度旋轉加速運動。 android:interpolator="@android:anim/accelerate_interpolator" android:fromDegrees="+360" android:toDegrees="0" android:pivotX="50%" android:pivotY="50%" android:ration="2000" /> 復制代碼 代碼實現 import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; public class RotateActivity extends Activity { /**向左旋轉動畫按鈕**/ Button mButton0 = null; /**向右旋轉動畫按鈕**/ Button mButton1 = null; /**顯示動畫的ImageView**/ ImageView mImageView = null; /**向左旋轉動畫**/ Animation mLeftAnimation = null; /**向右旋轉動畫**/ Animation mRightAnimation = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.retate); /**拿到ImageView對象**/ mImageView = (ImageView)findViewById(R.id.imageView); /**載入向左與向右旋轉動畫**/ mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft); mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright); mButton0 = (Button)findViewById(R.id.button0); mButton0.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { /**播放向左旋轉動畫**/ mImageView.startAnimation(mLeftAnimation); } }); mButton1 = (Button)findViewById(R.id.button1); mButton1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { /**播放向右旋轉動畫**/ mImageView.startAnimation(mRightAnimation); } }); } }