0

I have created a shape in my Android project and I would like to add a button on the top left corner.

This is my shape:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent" />
    <stroke android:width="1dp" android:color="#000000" />
    <padding android:left="2dp" android:top="1dp" android:right="2dp"
        android:bottom="1dp" />
</shape>

I add a screenshot to have more explication :

enter image description here

I want the cross at the top left corner of my rect but as you can see it's not that actually :(.

Thanks in advance for your help.

Onik
  • 19,396
  • 14
  • 68
  • 91

1 Answers1

0

After a Long Discussion with you, I just add a Shape Right and Below to crossImageButton in Relativelayout as a parent.

Here i have shared the code, Do the needed modification as your requirement

        RelativeLayout parent = (RelativeLayout)findViewById(R.id.parent);
        ImageButton ib = new ImageButton(getApplicationContext());
        ib.setId(1);
        ib.setBackgroundResource(R.drawable.cross_button);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        ib.setLayoutParams(lp);
        parent.addView(ib);

        ImageView iv = new ImageView(getApplicationContext()); 
        iv.setBackgroundResource(R.drawable.myshape);
        iv.setImageResource(R.drawable.ic_launcher);
        RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(50,50);
        lp1.addRule(RelativeLayout.RIGHT_OF, ib.getId());
        lp1.addRule(RelativeLayout.BELOW, ib.getId());
        iv.setLayoutParams(lp1);
        parent.addView(iv); 
  • thank you but what i had you said, i move my imageview with my finger, and i'm not sure that it's possible with a relative layout –  Nov 14 '13 at 15:57
  • No problem What kind of container you are use. Refer @ http://stackoverflow.com/questions/9398057/ and http://stackoverflow.com/questions/1660150/ – Subramanian Ramsundaram Nov 14 '13 at 16:50
  • If i use your example, i will use a relative layout. however with your links, it's just to move view not layout. is it the same work? –  Nov 15 '13 at 08:32