activity页面:
public class ThriedActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mTv1;
private Button mMBt_but1;
private Button runtoright;
private int first = 0;
private int second = 1500;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thired);
initView();
mMBt_but1.setOnClickListener(this);
TranslateAnimation animation = new TranslateAnimation(first, second, 0, 0);
animation.setRepeatCount(20);
animation.setDuration(2000);
runtoright.setAnimation(animation);
}
private void initView() {
mTv1 = (TextView) findViewById(R.id.tv1);
mMBt_but1 = (Button) findViewById(R.id.btn1);
runtoright = (Button) findViewById(R.id.runtoright);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn1:
new Thread(new Runnable() {
@Override
public void run() {
//让主线线程睡
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// int sum = 10;
// mMBt_but1.setText("显示:" + sum);
new ChangeAsyncTask().execute();
}
}).start();
break;
}
}
private class ChangeAsyncTask extends AsyncTask{
@Override
protected Object doInBackground(Object[] objects) {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
int sum=10;
return sum;
}
@Override
protected void onPostExecute(Object o) {
mMBt_but1.setText("显示:" + o.toString());
super.onPostExecute(o);
}
}
}
xml页面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="@+id/runtoright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="向右移动"/>
</LinearLayout>
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn9"/>
</LinearLayout>
875

被折叠的 条评论
为什么被折叠?



