2015-02-10 72 views

回答

0

您可以使用ImageView.bringToFront();,也许是最好的解决方案。

这里的Tutorial

让我知道如果你有任何问题。

0

可以使用的RelativeLayout:

RelativeLayout rv = (RelativeLayout) findViewById(R.id.my_ph); 
RelativeLayout.LayoutParams params; 
ImageButton im1 = new ImageButton(this); 

im1.setBackgroundResource(R.drawable.lamp); 
im1.setId(i); 
im1.setOnClickListener(new OnClickListener() { 
public void onClick(View v) { 
    TextView tx = (TextView) findViewById(R.id.textView1); 
    tx.setText("lamp #" + v.getId()); 
} 
}); 

params = new RelativeLayout.LayoutParams(40, 40); 
params.leftMargin = x; 
params.topMargin = y; 
rv.addView(im1, params); 

XML布局:

<RelativeLayout 
     android:id="@+id/my_ph" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="bottom"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/map" /> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_below="@+id/image" 
     android:layout_alignParentLeft="true"> 
</TextView> 

</RelativeLayout> 
0

如果要创建通过代码的图像,你可以使用的LayoutParams给第二图像负LEFTMARGIN。

RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams 
      (RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT); 
    imageParams.leftMargin = -20; // change this value 
    imageParams.addRule(RelativeLayout.RIGHT_OF,image1.getId()); 
    image2.setLayoutParams(imageParams); 

这将强制第一个图像上的第二个图像。通过更改左边距,您可以决定第二张图像在第一张图像上的移动量。

相关问题