How to set image1 overlap image2
I want to set image1(by Drawable) overlap image2(by bitmap)
example
In the example above
icon play is image1 and picture is image2
I found slove is only image1 and image2 is by drawable
and If image2 is by bitmap ,I have no idea to set it
ps. sorry my english is not good.
file.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="#+id/image_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bacground_pic"
/>
<ImageView
android:id="#+id/image_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="trues"
/>
</RelativeLayout>
secondly you have to set Bitmap to second image with this
ImageView image_1=(ImageView) findviewbyid(R.id.image_1);
image_1.setImageBitmap(bitmap);
On ImageView object you can set a background image and as well as the ImageResource. Another way of doing this is RelativeLayout, place two ImageView overlapping each other.
ImageView having extra properties to set extra bitmap or icon or drawable other than normal Background in View properties,
So for your case, you can set Play icon as src(which will come on top of background and center) and Bitmap you can set as Background
<ImageView
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/msg_media_play_small_icon" >
</ImageView>
and to set the Background Image, don't use imageView.setImageBitmap
use imageView.setBackground
imageview.setBackground(new BitmapDrawable(context.getResources(), bitmap));
Related
I'm trying to take a thumbnail image of a video the user can view in the app and display it in an ImageView. However, when I try to display the thumbnail, it looks like the whole ImageView disappears and no image appears at all.
I tried using a test photo that wasn't a thumbnail, and it definitely displayed in the ImageView, so I don't think it's a problem with the XML, but it could be. I've googled for hours and don't understand where I'm messing up. My code comes from Stack Overflow already.
uri = Uri.parse("android.resource://"+ getActivity().getPackageName() +"/"+R.raw.test);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(uri.getPath(), Thumbnails.MICRO_KIND);
//Create ImageView to hold the thumbnail
ImageView imageView = view.findViewById(R.id.mediaPreview);
imageView.setImageBitmap(thumb);
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/startup_dialog"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="25"
tools:context=".ui.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/getting_started"
android:gravity="start"
android:layout_gravity="start"/>
<ImageView
android:id="#+id/mediaPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
/>
The image would be displaying but it is not showing because you may have a image of greater pixel try changing your image pixel or try to add another image instead.
bitmap.setWidth(imageview.getWidth());
bitmap.setHeight(imageview.getHeight());
imageview.setImageBitmap(bitmap);
Why is this not working? I can load the bitmap, but i can't set the size to the size of an imagebutton or imageview.
If you want your bitmap fits to your ImageView, you can use one of the following ways.
1. Change in xml layout file
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
2. Change in java code
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageview.setImageBitmap(bitmap);
Is it possible to show multiple drawables (with margins in between them) inside an ImageView without using a frame layout + any unnecessary nesting? How can following be achieved?
Each drawable to appear as normal without any resizing
Only drawableA and drawableB to have 10dp margin on the end/right
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/myImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/myTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Java
Resources r = getContext().getResources();
int tenDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, r.getDisplayMetrics());
ImageView customIV = content.findViewById(R.id.myImgView);
Drawable drawableA = getResources().getDrawable(R.drawable.ic_happyface);
Drawable drawableB = getResources().getDrawable(R.drawable.ic_neutralface);
Drawable drawableC = getResources().getDrawable(R.drawable.ic_sadface);
customIV.addView(?);
An ImageView only houses a single Drawable. Multiple ImageViews are needed to display multiple Drawables.
You could replace the root LinearLayout with a RelativeLayout to avoid nesting.
I have a relative layout:
RelativeLayout battle_layout = (RelativeLayout) findViewById(R.id.battle);
I need to attach here a child (a JPG image from resources/drawable).
I was writting in c# and javascript earlier, but here it's a bit harder to accomplish :)
Is there someone who could help me? Thanks!
Maybe you can use one of these options. programmatically or in xml:
Add a ImageView to your layout
Set the image as background of your layout
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/YOUR_IMAGE">
<ImageView
android:src="#drawable/YOUR_IMAGE"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Code
ImageView imageView = new ImageView(this);
image.setImageResource(R.drawable.YOUR_IMAGE);
battle_layout.addView(image);
I have an app which counts up from 1 to 100, showing the count-up on the screen.
I have a custom font. The problem is that the numbers keep jumping left and right as it counts up. I draw the numbers by drawing on a canvas, using graphics.Paint.
How can I set the font to be fixed and not jumping around?
You will either have to use a fixed width font or put the individual digits in a custom layout with fixed widths.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/digit1"
android:layout_width="0dp"
android:layout_weight="0.5"
android:gravity="center_horizontal|center_vertical" />
<TextView
android:id="#+id/digit2"
android:layout_width="0dp"
android:layout_weight="0.5"
android:gravity="center_horizontal|center_vertical" />
</LinearLayout>
Set the typeface using your custom font like this:
private void setLogoTypeface()
{
AssetManager assetManager = getContext().getAssets();
Typeface tf = Typeface.createFromAsset(assetManager,"GILB.TTF");
logo = (TextView)findViewById(R.id.logo);
logo.setTypeface(tf);
}
Substitute your font name and the textview should render the font.