How to get a thumbnail to fit inside an imageview? - android

I am getting thumbnails from a video that i just recorded and I need to get the thumbnail to fit into an imageview. I am using this to call the thumbnail :
Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
And I am using this to call the imageview:
image.setImageBitmap(curThumb);
My xml for my imageview looks as such:
<ImageView android:id="#+id/iView" android:paddingRight="10px" android:layout_height="280dp" android:layout_width="320dp" android:layout_gravity="center_horizontal" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="#drawable/border"></ImageView>
The Border that I am using for my background of the image view is an xml which gives the view a nice white border frame, this is follwing xml for it:
<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="oval">
<stroke android:width="3dp" android:color="#ffffff" />
<padding android:left="0px" android:top="1dp" android:right="0px"
android:bottom="1dp" />
</shape>
I don't know if its because I am using a MINI_KIND thumbnail but i need to cut it down by a little so it can fit into the imageview perfectly. Any help will suffice. Thanks in advance.

Try adding android:scaleType="fitCenter" to the ImageView's attributes.
This will center the image and ensure that (assuming it's larger than the ImageView's area) the image covers the entire area and that the image is completely visible along at least one axis.

Set your scaletype to centercrop http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

Related

Splashscreen image fullsize aspect ratio

I have problem with setting image to full width and full height with right aspect ratio. I have this piece of code and don't now how to solve it, if it's possible.
Thank you
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="fill">
<item>
<bitmap android:gravity="center|fill_vertical" android:src="#drawable/background" />
</item>
</layer-list>
Why are you using layer-list? You could use a RelativeLayout and use the following settings within the RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_background_image"
android:scaleType="centerCrop"
This android:background will put a background image (don't forget to replace this with your own image) and the rest options will make a full size background.

Button with distinct corners and an Image at centre

I need a button with left side rounded corners and right side flat corners.
complete rounded corners is possible with this code:
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp"/>
Resultant image:
Now I need an image similar to following one:
I've tried the follwing code:(Sorry..This is an answer.But it was not reflecting in Xml)
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
But it is the not the correct one.
To centre an image I tried the following code:
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/border2"
android:layout_weight="0.5"
android:layout_margin="10dp"
android:paddingRight="50dp"
android:paddingLeft="50dp"
android:drawableRight="#drawable/facebook" />
This fixed an image at centre.But is there any other way to do it?
If nothing else helps, you can use a 9-patch image.

Resize ImageView background accordingly to Image size

I am trying to have the background of the image re-size accordingly to the Image size
I have a simple ImageView
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:background="#drawable/white_bg"
android:scaleType="fitCenter"
android:padding="3dp"
android:layout_height="wrap_content" />
The white_bg is an xml drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#android:color/white" />
<corners android:radius="5dp" />
</shape>
The Problem is that there are large white spaces between the image and the background.
The only thing appeared to solve the problem was setting the `ScaleType' attribute to FitXY but it stretches small images and they turn to be ugly.
I have also tried adding a LinearLayout parent to the ImageView with `wrap_content' width and height attributes but there were still large white spaces with some of the images.
Try this
ImageView.setAdjustViewBounds(true);
not sure but it helps you

how do I show circular cut of image in android

I have a rectangular image that I want to appear circular in an ImageView? I tried the following to no avail.
I create a circular xml shape and apply it as the background of my ImageView. Then I add the png image as the src of the ImageView. But the image still appears rectangular in a circular view. When I try to scale the image in the view, it simply fills the view and forces the view to look rectangular. Of course I just want to effectively get a circular cross-section of the image, losing all four straight edges. I welcome any help.
<ImageView android:id="#+id/circular_content"
android:background="#drawable/bkg_circle_shape"
android:src="#drawable/img_1"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="oval" >
<solid android:color="#CCFFFFFF" />
<size
android:height="300dp"
android:width="300dp" />
</shape>
try it splitTrack=-false in api21 or higher
for SeekBar, i test it work correctly.

Android Rounded Corner for Button not working

I am trying to create a ImageButton for my user portrait.
<ImageButton
android:id="#+id/new_question_user_portrait"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/oler_login_submit_button_bg"
android:src="#drawable/oler_portrait"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
This is the background xml file.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
My src image is 200*200 px. Round Corner still not working for these code.
Could anyone show me the correct way to create a rounded Image Button with fixed height and width regardless of image source?
You are expecting the background drawable to work as a mask, which it does not. The drawable is drawn behind the bitmap (after all, it's a background), so it's invisible.
What you are looking for is a mask, have a look at this question and its answers: Mask ImageView with round corner background

Categories

Resources