Hi,

I want to use a custom view (contains a bitmap) to put a bitmap where
i want on the screen (i want to build a custom design for the
application). I do a little project who explains the problem. I want
to move the view from the corner top/left to 100px. I use a
RelativeLayout in my main layout and a MyCustomView to draw the
bitmap.

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:id="@+id/relativeLayout"
        android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">

</RelativeLayout>

MyCustomView :
public class MyCustomView extends View {

    private Bitmap mBugdroid;

    public MyCustomView(Context pContext) {
        super(pContext);
        mBugdroid = BitmapFactory.decodeResource(getResources(),
R.drawable.bugdroid);
    }

    @Override
    protected void onDraw(Canvas pCanvas) {
        pCanvas.drawBitmap(mBugdroid, 0, 0, null);
    }

}

Activity :
public class TestMarginActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        RelativeLayout mainLayout = (RelativeLayout)
findViewById(R.id.relativeLayout);
        MyCustomView customView = new MyCustomView(this);
        // Settings here the margin : Doesn't works!
        MarginLayoutParams mLayoutParams = new MarginLayoutParams(338,
338);
        mLayoutParams.setMargins(100, 100, 0, 0);
        customView.setLayoutParams(mLayoutParams);
        mainLayout.addView(customView, 0, mLayoutParams);
    }
}

It doesn't work... the bitmap stays on the left/top corner of the
application. I don't know why...

Can you help me ?

Regards.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to