I need to show an image in an imageview but not complete, just need a preview as seen in the image.
I have this code but it shows the complete image not a preview
xml code
<ImageView
android:id="#+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:contentDescription="#string/img_adjunta" />
kotlin code
imageView2.setImageURI(Uri.fromFile(fileComprimido))
Related
I'm using Glide library to get user's profile image from url and display it in ImageView view.
I want to set camera icon on the right side of that profile image exactly like below.
Here is my imave view:
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="700dp" />
Glide:
ImageView imageView = findViewById(R.id.imageView);
Glide.with(imageView)
.load(URL)
.circleCrop()
.placeholder(setCircularImage(R.drawable.prof))
.error(setCircularImage(R.drawable.t))
.fallback(setCircularImage(R.drawable.camera_red))
.into(imageView);
How could I do that, Whic library should I use to make camera icon on the right side of a profile image ?
I don't want the icon overlap the profile image. I want the profile image to be cropped to give place to camera icon(Like on facebook app profile image). Thanks.
Thanks.
There is nothing to do with Glide. You can use ConstraintLayout, FrameLayout or RelativeLayout to overlap ImageViews.
you can use Relative layout to achieve this like below
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_launcher_background"
android:layout_marginTop="700dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_alignBottom="#id/imageView"
android:layout_alignEnd="#id/imageView"
android:layout_height="wrap_content"
android:bott="true"
android:src="#drawable/abc_vector_test"
/>
</RelativeLayout>
and then adjust it accordingly.
Happy coding :)
first you should use circleImageView in your layout and then set two of them like this:
<CircleImageView
android:id="#+id/circleImg1"
android:layout_width="50dp"
android:layout_height="50dp"/>
<CircleImageView
android:id="#+id/circleImg2"
android:layout_width="15dp"
android:layout_alignBottom="#id/circleImg1"
android:layout_alignEnd="#id/circleImg1"
android:layout_height="15dp"/>
I have to take a picture in my App. After take it , I have to show it in a ImageView, so I decided to use Glide as library to handle it.
I have set the code like this:
Glide.with(this)
.load(mLastPhoto)
.fitCenter()
.centerCrop()
.into(iv_circ_image);
and the xml file looks like:
<ImageView
android:id="#+id/circ_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bTakePicture"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="12dp"
android:src="#drawable/ab_background_textured_" />
But when the phot has been taken, the image is shown like this:
How I have to set the Glide code or the XML to show all the image?
Add the android:adjustViewBounds="true" attribute to your ImageView. Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable (from API-Documentation http://developer.android.com/reference/android/widget/ImageView.html).
<ImageView
android:adjustViewBounds="true"
android:id="#+id/circ_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bTakePicture"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="12dp"
android:src="#drawable/ab_background_textured_" />
In the xml you have android:layout_height="wrap_content" and android:layout_marginTop="12dp"
Then in the java you have .fitCenter().centerCrop().
So basically you have a 12dp image view that Glide is filling. I suggest you set the height of the image view (ie 200dp) or have the buttons stick to the bottom of the screen and have the imageview fill the available space between them.
I have an image picker application that selects images from gallery. If the image doesn't have a particular width/height ratio I display a small warning symbol on top of the image.
In my XML View File I have two ImageView views. It is below:
view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp" >
<ImageView
android:id="#+id/imgQueue"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="centerCrop" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/wrongimagesign"
android:src="#drawable/error"
android:layout_alignTop="#+id/imgQueue"
android:layout_alignRight="#+id/imgQueue"
android:layout_alignEnd="#+id/imgQueue"
android:visibility="invisible"/>
</RelativeLayout>
The images are displayed in a gridview so in my adapter i have this code:
ImageLoader.getInstance().displayImage("file://" + image.cardPath, imgQueue);
**Bitmap bitmap = ImageLoader.getInstance().loadImageSync("file://" + image.cardPath, Utility.displayImageOptions);**
wrongImageSign.setVisibility(imageRatioIsBad(bitmap) ? View.VISIBLE : View.INVISIBLE);
The problem is that since i am loading the bitmap the performance is very slow (it takes too long to load the image and display the warning sign). Is there a way to improve the performance.
In Android, preferably in XML is it possible to overlay an image around another image?
I have an image which is a blue circle and My app retrieves an icon from an API. After the icon has been retrieved it is displayed via an ImageView.
The XML for the ImageView is:
<ImageView
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100dp"
android:id="#+id/weather_icon"
android:scaleType="fitCenter"/>
Now I would like to "wrap" an image around this image. The XML for the image I want around the retrieved image is:
<ImageView
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:src="#drawable/image_wrap"/>
I have an image button with the following xml:
<ImageButton
android:id="#+id/imageButton1"
android:contentDescription="#string/button_click1"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:src="#drawable/button_default" />
Now I want to dynamically change the image source from loading a file. I know the right way is to use
this.button.setImageDrawable(this.default_source);
The problem is I want to make sure two things:
1. The new image should be in the same place as before replacing.
2. If the newly loaded image is not 200dp * 100dp, I want automatically scale the
image not cutting it. Any idea how to do this?
Thanks a lot!!!
Put the following xml attribute into your ImageButton xml...
android:scaleType="fitXY"
as below...
<ImageButton
android:id="#+id/imageButton1"
android:contentDescription="#string/button_click1"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="#drawable/button_default" />