android移动view之后刷新布局导致移动后的view归回原位置2

本文探讨了在Android开发中遇到的一个问题:更新布局后,移动的View会回到初始位置。通过分析代码片段,可以看到涉及到对View的位置调整以及文本更新。为了解决View移动后不复位的问题,开发者需要正确处理布局更新和View位置的改变。
摘要由CSDN通过智能技术生成

接上篇
布局文件






<!--<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();

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值