如何放置的图像在一个又一个在Android上的应用程序? [英] how to place an image over another one on android app?

查看:75
本文介绍了如何放置的图像在一个又一个在Android上的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以把IM2在正确的位置

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);

我的布局

<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>

我想,IM1将在ImageView的顶部位置的x,y

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

推荐答案

和答案......

 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布局:

XML Layout:

 <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>

这篇关于如何放置的图像在一个又一个在Android上的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆