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

后端 未结 4 1488
予麋鹿
予麋鹿 2020-12-17 04:47

how i can put im2 in the correct place

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


    ImageView im1 = new ImageView(this);
    im1.setBackgrou         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 05:13

    and the answer....

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

     
        
        
        
    
     
    

提交回复
热议问题