RelativeLayout et positionnement d'un bitmap
Bonjour,
Je cherche à créer un View qui contient une image qui sera placée au centre du téléphone. J'ai fait un petit test avec un projet mais je n'arrive pas à décoller mon image du bord haut-gauche de mon téléphone.
Voici le code :
main.xml
Code:
1 2 3 4 5 6 7
| <?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 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
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 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| 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);
MarginLayoutParams mLayoutParams = new MarginLayoutParams(338, 338);
mLayoutParams.setMargins(100, 100, 0, 0);
customView.setLayoutParams(mLayoutParams);
mainLayout.addView(customView, 0, mLayoutParams);
}
} |
Quelle est la solution pour déplacer cette vue de 100 pixel du bord droit et haut de mon mobile ? Cela fait 1 journée que je bloque sur le problème et je sature :(