Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

how to place an image over another one on android app?

how i can put im2 in the correct place

FrameLayout rv =(FrameLayout)findViewById(R.id.my_ph);


    ImageView im1 = new ImageView(this);
    im1.setBackgroundResource(R.drawable.lamp_on);
    im1.layout(100, 100,120, 120);

    rv.addView(im1);

my layout

<FrameLayout android:id="@+id/my_ph" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView  
android:id="@+id/image"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/sketch" />
</FrameLayout>

i want that im1 will be on top of the ImageView in position x,y

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In layout add one more ImageView and align Top, Bottom, Right, Left to first one. Make it invisible;

<FrameLayout android:id="@+id/my_ph"    
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView  
    android:id="@+id/image"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/sketch" android:layout_alignParentTop="true"/>
<ImageView  
    android:id="@+id/image2"
    android:layout_width="fill_parent" 
    android:layout_height="fill_paren" 
    android:layout_alignTop="@id/image"
    android:layout_alignLeft="@id/image"
    android:layout_alignRight="@id/image"
    android:layout_alignBottomp="@id/image"
    android:visibility="INVISIBLE"/>
</FrameLayout>

Then in code:

ImageView image2 =(ImageView)findViewById(R.id.image2);
image2.setVisibility(View.VISIBLE);
image2.setImageResource(R.drawable.my_image);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...