动画中的View的点击判断
http://blog.csdn.net/seker_xinjian/article/details/7236945
Android 动画框架详解
http://www.ibm.com/developerworks/cn/opensource/os-cn-android-anmt1/index.html
每次点击往前100或往后100.
package com.ql.app; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.LinearInterpolator; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.ImageView; public class App extends Activity { private Button btn_0,btn_1; private ImageView iv; private int count; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iv = (ImageView)findViewById(R.id.iv); iv.bringToFront(); btn_0=(Button)findViewById(R.id.btn_0); btn_0.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub TranslateAnimation animation = new TranslateAnimation(count*100, 100+count*100, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(400); animation.setFillAfter(true); iv.startAnimation(animation); count++; } }); btn_1=(Button)findViewById(R.id.btn_1); btn_1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub TranslateAnimation animation = new TranslateAnimation(count*100, -100+count*100, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(400); animation.setFillAfter(true); iv.startAnimation(animation); count--; } }); } }
android 自定义Animation
http://lipeng88213.iteye.com/blog/1199120
http://www.ophonesdn.com/article/show/185
简单循环动画的实现:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:interpolator="@android:anim/linear_interpolator" android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="2000" android:repeatCount="infinite" android:repeatMode="reverse" /> </set> <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <translate android:fromXDelta="0" android:toXDelta="100%" android:duration="2000" android:repeatCount="infinite" android:repeatMode="reverse" /> </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="2.0" android:fromYScale="1.0" android:toYScale="2.0" android:pivotX="50%" android:pivotY="50%" android:duration="2000" android:repeatCount="infinite" android:repeatMode="reverse" android:interpolator="@android:anim/linear_interpolator" /> </set>
使用:
import android.app.Activity; import android.os.Bundle; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.TextView; public class App extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha); Animation translate = AnimationUtils.loadAnimation(this, R.anim.anim_translate); Animation scale = AnimationUtils.loadAnimation(this, R.anim.anim_scale); TextView tv=(TextView)findViewById(R.id.tv); tv.startAnimation(alpha); ImageView iv0=(ImageView)findViewById(R.id.iv0); ImageView iv1=(ImageView)findViewById(R.id.iv1); ImageView iv2=(ImageView)findViewById(R.id.iv2); iv0.startAnimation(alpha); iv1.startAnimation(translate); iv2.startAnimation(scale); } }
在飞行模式下:检测是否有网络,有则返回activeNetInfo,没有返回null
/** * read the info of network */ private NetworkInfo getAvailableNetWorkInfo(YyBackUpActivity activity) { ConnectivityManager connectivityManager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); /* check network status */ NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); /* check network status if it is available */ if (activeNetInfo != null && activeNetInfo.isAvailable()) return activeNetInfo; return null; }
检查是否有网络时先判断是否是飞行模式:
//是否飞行模式
static boolean isAirplaneModeOn(Context context) {
return android.provider.Settings.System.getInt(context.getContentResolver(),
android.provider.Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
下面是我在一个程序中调用上面两个方法
//如果是飞行模式
if (isAirplaneModeOn(context)) {
//如果连接的方式可用并且不为空
if (getAvailableNetWorkInfo(context)!=null&&getAvailableNetWorkInfo(context).isAvailable())
YyBackUpGF.showToast(context, R.string.msg_latest_version_tip);
//为空的时候
else {YyBackUpGF.showToast(context,R.string.menu_update_failed);}
}
//不是飞行模式时
else {YyBackUpGF.showToast(context,R.string.menu_update_failed);
}
一定要加下面两个权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
在创建UIButton时,点击动作里老是读取不到成员变量。调试N次,一到读取那个列表时程序就直接退出。
-(void)selectCompany:(id)sender{ int index = [sender tag]; //NSLog(@"sender:%d",index); NSArray *company = [companyList objectAtIndex:index]; //NSLog(@"selectCompany:name:%@,id:%@",[company valueForKey:@"name"],[company valueForKey:@"cid"]); CompanyMatchController *cMatch = [[CompanyMatchController alloc]initWithCidAndName:[company valueForKey:@"cid"] cName:[company valueForKey:@"name"]]; [self.navigationController pushViewController:cMatch animated:YES]; }
就这是
NSArray *company = [companyList objectAtIndex:index];
这里程序就直接退出了。
经别人指数,因为你self.是对你那对象retain了一次,所以就好了
后来慢慢地检查成员变量的初始化。发现问题问题出自:
-(void)fetchData{ [self removeAllView]; companyList = [JSONParser loadData:@"http://3g.wapzq.com/odds/json/company.jsp" isAllValues:NO valueForKey:@"list"]; [[WaitDialog sharedWaitDialog]setLoadingLabel:@"正在构造界面..."]; [self makeView]; }
以下
companyList = [JSONParser loadData:@"http://3g.wapzq.com/odds/json/company.jsp" isAllValues:NO valueForKey:@"list"];
要加上self.
self.companyList = [JSONParser loadData:@"http://3g.wapzq.com/odds/json/company.jsp" isAllValues:NO valueForKey:@"list"];重新编译,运行,哦野。解决了整一个上午的问题。