2012-02-28 6 views
0

私はイメージビューと名前の位置をハードコードしているが、今、私はパーサセットのイメージの名前とポジションプログラム

からそれを取得しています前に、私は、体位のArrayListのを持って、私はから取得したX、Yおよび画像の名前、すなわちXML。今私はそれを私の位置とこの名前を割り当てているImageViewsのない相対レイアウトと子を持っている私のmain3.xmlレイアウトに割り当てたいと思います。

レイアウトやその他のアイデアを膨らませる必要がありますか?または私はここに私のmain3.xmlレイアウトが、これは今、私はコードを介して、それらのtopmargin_leftとトップを与えたい、ハードコード1である10の画像ビューをプログラム

を行う必要があります。..

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/Level1Layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="objectClick" 
      android:background="@drawable/hh_gmw_03"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="593dp" 
     android:layout_marginLeft="998dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image1" 
     android:src="@drawable/hht3l01"/> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="39dp" 
     android:layout_marginLeft="20dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image1" 
     android:src="@drawable/hht3l02" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="153dp" 
     android:layout_marginLeft="497dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image3" 
     android:src="@drawable/hht3l03" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="524dp" 
     android:layout_marginLeft="998dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image4" 
     android:src="@drawable/hht3l04" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="183dp" 
     android:layout_marginLeft="715dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image5" 
     android:src="@drawable/hht3l05" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="413dp" 
     android:layout_marginLeft="557dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image6" 
     android:src="@drawable/hht3l06" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="53dp" 
     android:layout_marginLeft="532dp" 
     android:onClick="objectClick" 
     android:contentDescription="Image1" 
     android:tag="Image7" 
     android:src="@drawable/hht3l07" /> 
</RelativeLayout> 

答えて

1

あなたはまだあなたを使用し続けることができmain3.xmlレイアウトとプログラムで余白を設定します。

  1. を「名」引数は"imageView" + iとして、いくつかのループ内で生成されるだろうResources.getIdentifier(..)方法、各ImageViewの識別子を検索します。
  2. ImageViewsの親の各ImageView
  3. ViewGroup.MarginLayoutParams.setMargins(..)とコール View.invalidate()、あなたのケースでは、それはLevel1Layout IDを持つ RelativeLayoutだのレイアウトパラメータを設定します。
+0

ありがとうございました。 – user1201239

関連する問題