如何在Android应用程序上放置另一个图像?

eya*_*alb 4 android android-layout

我怎么能把im2放在正确的地方

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);
Run Code Online (Sandbox Code Playgroud)

我的布局

<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>
Run Code Online (Sandbox Code Playgroud)

我希望im1将位于x,x位置的ImageView之上

Max*_*xim 11

在布局中添加一个ImageView并将顶部,底部,右侧,左侧对齐到第一个.让它看不见;

<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>
Run Code Online (Sandbox Code Playgroud)

然后在代码中:

ImageView image2 =(ImageView)findViewById(R.id.image2);
image2.setVisibility(View.VISIBLE);
image2.setImageResource(R.drawable.my_image);
Run Code Online (Sandbox Code Playgroud)