2010-11-21 7 views
0

このapplication.Iを使用して特定の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

まだまだこれについています。ありがとう –

答えて

0

でmyImage1の上にマーカー画像を移動することですこのコード:

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

あなたはsetPaddingを使うことができ、電話の幅と高さは上記のコードで得ることができます。ポジショニングの問題もあり、これが解決策でした。

+0

ええと、私はダミーです。イメージの位置を少し設定する方法を詳しく教えてください。 –

+0

何かについては正しくは見えません。通常のエミュレータのscreenWidth screenHeightは160と160を返します。 –

+0

これはどうやって使うのですか? –