2010-11-21 125 views
0

我想要得到一个图像移动到某些x和y与此应用程序。我已经尝试与layoutParams通过搜索,但它不工作在这里是我的完整的应用程序代码。LayoutParams移动x和y

main.xml中

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:screenOrientation="portrait"> 

    <ImageView android:id="@+id/ImageView01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scaleType="fitXY" android:src="@drawable/myImage1" android:layout_marginTop="5dp"></ImageView> 
    <FrameLayout android:id="@+id/FrameLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/marker" android:src="@drawable/marker"></ImageView> 
    </FrameLayout> 
</LinearLayout> 

MYAPP的Java

ImageView marker; 

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     marker=(ImageView)findViewById(R.id.marker); 
     FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); 
     lp.setMargins(35, 90, 0, 0); 
     marker.setLayoutParams(lp); 
     marker.invalidate(); 

     } 
} 

我的最终目标是要在不同的位置

+0

仍然卡住this.Thanks – 2010-11-21 07:14:29

回答

0

在myImage1移动标记图像可以拿到手机与大小此代码:

DisplayMetrics metrics = new DisplayMetrics(); 
    ((Activity)c).getWindowManager().getDefaultDisplay().getMetrics(metrics); 
    screenWidth = ((int)metrics.xdpi); 
    screenHeight = ((int)metrics.ydpi); 

您可以使用setPadding,通过上面的代码可以获得手机的宽度和高度。我也有定位问题,这是解决方案。

+0

嗯,好吧,我是一个假人,我想你可以详细说明如何设置图像的位置一点点。 – 2010-11-21 06:55:55

+0

有些东西只是看起来不正确。在普通模拟器中记录screenWidth screenHeight给出160和160. – 2010-11-21 07:13:17

+0

你应该如何使用它? – 2010-11-21 07:13:33