This is my layout which i tried so far without any success
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white"> <LinearLayout android:id="@+id/lltest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/inside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:layout_marginBottom="5dip" android:src="@drawable/frame"/> </LinearLayout> <ImageView android:id="@+id/outside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/inside_imageview" android:scaleType="fitXY"/> </RelativeLayout>
What i exactly want is to have my outside_imageview on top of inside_imageview with the exact height and width... How to do it through layout?
Android App Development for Beginners This example demonstrates how do I overlay two images In Android to set an ImageView. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.
ImageButton has the same property as ImageView . Only one feature is extra, which is, images set through ImageButton are clickable, and actions can be attached with them upon clicking. Just like a button, the setOnClickListener() can be used to set an event listener for click event on this.
You can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" > <ImageView android:id="@+id/inside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:src="@drawable/frame" /> <ImageView android:id="@+id/outside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/inside_imageview" android:layout_alignBottom="@id/inside_imageview" android:layout_alignLeft="@id/inside_imageview" android:layout_alignRight="@id/inside_imageview" android:scaleType="fitXY" /> </RelativeLayout>
The layout_align[Top|Bottom|Left|Right]
attribute in RelativeLayout
is used to align views based on their respective x and y values within the margin. The second ImageView
will now be aligned to the top, bottom, left, and right of the first ImageView
based on the margins. Padding is ignored in the alignment.
FrameLayout
is what you need. You can simply merge the parent layout that is a FrameLayout
too. Take a look at the Android Developers Blog: http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> <ImageView android:id="@+id/outside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY"/> <ImageView android:id="@+id/inside_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:layout_marginBottom="5dip" android:src="@drawable/frame" /> </merge>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With