2010-06-17 42 views
1

我的main.xml這個樣子的:如何移動的的ImageView在AbsoluteLayout到XY位置

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

我該怎麼做,如果我whant移動從球x=247dip, y=96dipx=100, y=100而我的應用程序正在運行?

回答

-1

第一組圖像的佈局高度和寬度Fillparent然後用下面的代碼

public void onWindowFocusChanged(boolean hasFocus) { 

     ball.scrollTo(10, 20); 
    } 
+0

不起作用 – 2010-09-10 18:23:55

-2
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 
0

看看here。它解釋瞭如何在android中使用絕對定位。

相關問題