在android中,按顺序执行两个任务
在我的计划中,基本原则是: 当程序打开时,将显示动画,然后显示饼图结果 我的代码是:在android中,按顺序执行两个任务,android,animation,Android,Animation,在我的计划中,基本原则是: 当程序打开时,将显示动画,然后显示饼图结果 我的代码是: public class Popup_animation11 extends Activity { private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN }; LinearLayout layout; private CategorySeries mSeries = new CategorySeri
public class Popup_animation11 extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
private TransparentProgressDialog pd;
private Handler h;
private Runnable r;
EditText name1,name2;
private int[] VALUES = {40 , 60 };
String x1,y1;
String[] NAME_LIST=new String[] { "mangoes","apples"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
h = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
r =new Runnable() {
@Override
public void run() {
if (pd.isShowing()) {
pd.dismiss();
}
}
};
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
pd.show();
h.postDelayed(r,5000);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}});
}
@Override
protected void onDestroy() {
h.removeCallbacks(r);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
@Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
}
}
}
公共类弹出窗口\u动画11扩展活动{
私有静态int[]COLORS=newint[]{Color.洋红,Color.CYAN};
线性布局;
私有类别系列mSeries=新类别系列(“”);
private DefaultRenderer mRenderer=新的DefaultRenderer();
private GraphicalView mChartView;
私有透明进程对话框pd;
私有处理器h;
私人运营商;
编辑文本名称1,名称2;
私有int[]值={40,60};
字符串x1,y1;
String[]NAME_LIST=新字符串[]{“芒果”、“苹果”};
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
h=新处理程序();
pd=新的TransparentProgressDialog(这个,R.drawable.uktrafficlights);
r=新的可运行(){
@凌驾
公开募捐{
if(pd.isShowing()){
pd.解散();
}
}
};
mrender.setApplyBackgroundColor(真);
mrender.setBackgroundColor(Color.argb(100,50,50,50));
mRenderer.setChartTitleTextSize(20);
mrender.setLabelsTextSize(15);
mrender.setLegendTextSize(15);
mRenderer.setMargins(新的int[]{20,30,15,0});
mrender.setZoomButtonsVisible(true);
mrender.设置起始角(90);
最终按钮btnOpenPopup=(按钮)findviewbyd(R.id.openpopup);
mChartView=ChartFactory.getPieChartView(this,mSeries,mrender);
btnOpenPopup.setOnClickListener(新建按钮.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
pd.show();
h、 后延迟(r,5000);
LayoutFlater LayoutFlater=(LayoutFlater)getBaseContext().getSystemService(布局\充气器\服务);
视图popupView=LayoutFlater.充气(R.layout.main\u piechart,null);
final PopupWindow PopupWindow=新的PopupWindow(popupView、LayoutParams.WRAP_内容、LayoutParams.WRAP_内容);
布局=(LinearLayout)popupView.findViewById(R.id.chart);
布局。添加视图(mChartView);
对于(int i=0;i
但问题是,当我打开程序时,动画正在运行,并且在后台结果也同时显示。我要一个接一个。首先是动画,然后是结果。我的代码中的问题在哪里?您需要为此使用。在onAnimationEnd
方法中编写显示数据的逻辑
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//here display data
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
希望这有帮助:)您需要使用它。在onAnimationEnd
方法中编写显示数据的逻辑
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//here display data
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
希望这对您有所帮助:)向您的
旋转动画添加动画监听器
,然后在onAnimationEnd
中向您的处理程序
发布代码以显示您的图表。向旋转动画添加动画监听器
,然后在onAnimationEnd
中,将代码发布到Handler
以显示图表。