overlay two images in android to set an imageview
You can skip the complex Canvas manipulation and do this entirely with Drawables, using LayerDrawable
. You have one of two choices: You can either define it in XML then simply set the image, or you can configure a LayerDrawable
dynamically in code.
Solution #1 (via XML):
Create a new Drawable XML file, let's call it layer.xml
:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/t" />
<item android:drawable="@drawable/tt" />
</layer-list>
Now set the image using that Drawable:
testimage.setImageDrawable(getResources().getDrawable(R.layout.layer));
Solution #2 (dynamic):
Resources r = getResources();
Drawable[] layers = new Drawable[2];
layers[0] = r.getDrawable(R.drawable.t);
layers[1] = r.getDrawable(R.drawable.tt);
LayerDrawable layerDrawable = new LayerDrawable(layers);
testimage.setImageDrawable(layerDrawable);
(I haven't tested this code so there may be a mistake, but this general outline should work.)
How to overlay image in layout in android
Use FrameLayout :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<ImageView
android:id="@+id/imgSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:src="@drawable/ic_launcher"/>
</FrameLayout>
Glide overlay two image urls into the same imageView
You cannot directly display two images in a single imageView without using a custom view.
If you want to use Glide and achieve similar functionality, place another ImageView just above your ImageView (By wrapping them in a FrameLayout or a RelativeLayout).
Then load overlay image in the ImageView at the top and set its alpha to 0.5 or any desired value.
how to half overlap imageview on another imageview in android
Simply you can use RealtiveLayout
and negative margins
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_landing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/screen_background">
<ImageView
android:background="@color/black"
android:id="@+id/img_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_below="@+id/img_background"
android:layout_centerHorizontal="true"
android:layout_marginTop="-40dp"<!-- negative margin to half of height -->
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
How to overlay 2 imageviews specifying the position
You can use FrameLayout to stack views on each other.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_green" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_red"/>
</FrameLayout>
then you may set android:layout_margin=""
to properly position the ImageView
s.
Note that the last child of FrameLayout
is the top most visible view
overlay canvas image with another image android
What about adding the second image over the first one?
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Bitmap temp = BitmapFactory.decodeResource(getResources(), R.drawable.floorplan);
image = Bitmap.createScaledBitmap(temp, canvas.getWidth(), canvas.getHeight(), true);
canvas.drawBitmap(image, 0, 0, null);
Bitmap over = BitmapFactory.decodeResource(getResources(), R.drawable.overlay);
image = Bitmap.createScaledBitmap(over, canvas.getWidth(), canvas.getHeight(), true);
canvas.drawBitmap(image, 0, 0, null);
}
Related Topics
Android Arraylist of Custom Objects - Save to Sharedpreferences - Serializable
How to Launch Activity Only Once When App Is Opened for First Time
Defining Z Order of Views of Relativelayout in Android
Google Maps Android API V2 - Detect Touch on Map
Failed to Resolve: Com.Google.Firebase:Firebase-Core:9.0.0
How to Disable Action Bar Permanently
Draw Multi-Line Text to Canvas
Android: How to Use Onbackpressed() with Toast
How to Get Camera Result as a Uri in Data Folder
Listview Reusing Views When ... I Don't Want It To
Couldn't Load Memtrack Module Logcat Error
Android: Out of Memory Exception in Gallery
Get Gps Location via a Service in Android
How to Convert Image File Data in a Byte Array to a Bitmap
How to Compile Android Application with System Permissions
Android Studio - Unexpected Top-Level Exception:
Google Map Signed API Key Errors in Android
Pass a String from One Activity to Another Activity in Android