接上篇
布局文件
<!--<TextView-->
<!--android:id="@+id/tt"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="test" />-->
<!--<ImageView-->
<!--android:layout_width="60dp"-->
<!--android:layout_height="60dp"-->
<!--android:layout_centerInParent="true"-->
<!--android:src="@drawable/app" />-->
<!--<ImageView-->
<!--android:id="@+id/ii"-->
<!--android:layout_width="60dp"-->
<!--android:layout_height="60dp"-->
<!--android:layout_centerInParent="true"-->
<!--android:src="@drawable/controlset_ic_launcher" />-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:gravity="center"-->
<!--android:orientation="horizontal">-->
<!--<Button-->
<!--android:id="@+id/Move"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="1"-->
<!--android:text="移动"-->
<!--android:textSize="20sp" />-->
<!--<Button-->
<!--android:id="@+id/MoveBack"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="1"-->
<!--android:text="退回"-->
<!--android:textSize="20sp" />-->
<!--</LinearLayout>-->
使用
public class MainActivity extends Activity {
int count;
TextView tt;
ImageView iv;
int dFX = 0, dTX = 50, dFY = 0, dTY = 50;
RefreshRelativeLayout mapViewRelativeLayout;
Button mMove;
Button mMoveBack;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
// iv.layout(l, t, r, b);
break;
case 1:
tt.setText(count++ + “”);
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapViewRelativeLayout = (RefreshRelativeLayout) findViewById(R.id.MapView_Layout);
tt = (TextView) findViewById(R.id.tt);
iv = (ImageView) findViewById(R.id.ii);
mMove = (Button) findViewById(R.id.Move);
mMoveBack = (Button) findViewById(R.id.MoveBack);
mMove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapViewRelativeLayout.setTargetViewLayout(dFX, dTX, dFY, dTY, 1000, 100, false);
}
});
mMoveBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapViewRelativeLayout.setTargetViewLayout(dFX, -dTX, dFY, -dTY, 1000, 100, false);
}
});
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
handler.sendEmptyMessage(1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}