繁体   English   中英

如何将AbsoluteLayout中的ImageView移动到XY位置

[英]How do I move an ImageView in AbsoluteLayout to X Y position

我的main.xml看起来像这样:

<AbsoluteLayout
   android:id="@+id/AbsoluteLayout01"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android"> 

   <ImageView
      android:layout_height="wrap_content"
      android:layout_x="247dip"
      android:layout_width="wrap_content"
      android:layout_y="96dip"
      android:id="@+id/Ball"
      android:src="@drawable/ball"/>

</AbsoluteLayout>

和Java

ball = (ImageView) findViewById(R.id.Ball);

如果我想在应用运行时将球从x=247dip, y=96dip移到x=100, y=100怎么办?

首先将图像的布局高度和宽度设置为Fillparent,然后使用以下代码

public void onWindowFocusChanged(boolean hasFocus) {

        ball.scrollTo(10, 20);
    }
ball.setLeft(10); //this moves view 10 pixel to left
ball.setLeft(-10); //this moves view 10 pixel to right
ball.setRight(10);//this moves view 10 pixel to right

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM