Reputation: 268
i have couple of imageViews that i create programmatically, so here is my question, if i want to put one imageView on the other, how can i tell my app which imageView is going to be on top, and which one on the bottom ? This is how i create ImageViews, and that works fine.
image = new ImageView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
image.setScaleType(ImageView.ScaleType.MATRIX);
image.setImageResource(R.drawable.ic_launcher);
image.setId(1);
params.setMargins(0, 0, 0, 0);
Let's get the root layout and add our ImageView
((ViewGroup) mainLayout).addView(image, params);
Upvotes: 2
Views: 5501
Reputation: 268
So this is what helped me in the end, i am gonna put it so it may be of use to someone else.
You can use this: http://developer.android.com/reference/android/view/View.html#bringToFront%28%29
Just use it like this
YourImageView.bringToFront();
After you created both of the images and you need to put one on top. This works for most Views.
Upvotes: 4
Reputation: 10550
If you want to draw ImageViews on top of each other then you should use a FrameLayout
. This is a layout that draws views like a stack, the first child will be drawn first and others will be drawn on top of the previous. For example:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView1 ... />
<ImageView2 ... />
</FrameLayout>
If your layout is like this, and ImageView1 and ImageView2 overlap, then ImageView2 will be drawn over ImageView1 because it is the second child and is drawn last.
Upvotes: 2