There's an ImageView with certain size (100dp, 100dp). And there's an image which size is 1000-1000px.
That's how it looks right now:
1
What i want is:
2
So image wont come out of ImageView's borders and will be sort of zoomed to center in some value, that i can change. Can it be done in some way? Maybe i need something different from ImageView? At the moment, i use adapter for recyclerview, which loads list of items that contain an image that needs to be kinda zoomed.
<ImageView
android:id="#+id/cart_item_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/min" />
just add android:scaleType="centerCrop"
here is the code look like:
<ImageView
android:id="#+id/cart_item_image"
android:layout_margin="5dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerCrop" />
Related
I am making a chat application. For that, if the message is of image type, I want to wrap the height and fix the width. But the problem is that since image takes some time to load, there is a shift in chat messages until the image is loaded and so there is a jerk. How do I handle this?
<android.support.constraint.ConstraintLayout
android:id="#+id/parent_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/send_message_box"
android:maxWidth="228dp">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/iv_message"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="200dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:padding="11dp"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>
This is the image layout I am using.
You could fix the height and display a placeholder image till the image gets loaded. You get this functionality of displaying a placeholder image(till the image gets loaded) with Picasso, check this https://square.github.io/picasso/
You can set up an initial height using a default image while your images are getting downloaded. After the image is downloaded, it will take the height of the image if you set the height as wrap_content. Hence you need to modify your ImageView like the following.
<ImageView
android:id="#+id/iv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#mipmap/ic_image_loader_placeholder" />
Please modify the ImageView as per your requirement.
You might also look at this Github project where I have implemented a similar idea. I had to call an API of Flickr and load the images into the RecyclerView. Hope that helps!
I wan to place Small ImageView on the anchor of CircularView just like below image
My Code is
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.hey.heypickup.UI.UICircularImage xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/contct_imgpic"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_margin="5dp"
android:layout_weight="0.04"
android:padding="10dp"
app:line_color="#color/colorPrimary"
app:line_color_press="#color/green"
android:src="#drawable/ph_1"
app:line_width="1dp"
app:padding="0dp"/>
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="bottom|end"
android:src="#drawable/ic_phone_black"
/>
</FrameLayout>
Result of above code:
but the Second imageview not appearing at the achor of circularImageView?
Can we achieve this without using floating action button ?
if yes then how ?
Since your second image is overlapping the first image,
I think it's because your ImageView has a wrap_content height and width. You should make it a fix size, and try it out because if your ic_dialog_email image is large enough then it will take entire space and might overlap the first image.
Would you make height and width fix and try again? For example, make it 15dp each and take a look. Also remove that margin from ImageView along with that change.
You'll just need to trial and check the exact size your need for the second image along with required margin to position itself correctly as per your UI requirements
I would like to know how you adjust the "hitbox" of an ImageView to the Image inside, so that there are no empty spaces around the image. I want to make a game and so it feels odd when you click on an empty space next to the Image but it still counts as "a click on the image". I would really appreciate help.
Thank you in advance.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/soraka"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="#drawable/image"
android:adjustViewBounds="true"
android:maxWidth="300dp"
android:maxHeight="300dp"
android:scaleType="fitXY"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:cropToPadding="false"
android:padding="0dp" />
First of all open your image in some image editor and check if it fills entire canvas. Second - use android:scaleType="fitXY". But be carefull with aspect ratio:
Scale in X and Y independently, so that src matches dst exactly. This
may change the aspect ratio of the src.
Also remove all paddings, margins from ImageView.
I am loading an image from the web with a AsyncTask class and set it to a imageview in my code.
// loading of the image into the ImageView
new DownloadImageTask(MyImageView).execute("ImageURL");
the problem is, every time I load an image, the height of it is different, even though the width and height of the ImageView is warp_content.
I added sort of a border line with the Background and padding to see the actual height of it.
Here is the xml
<ImageView
android:id="#+id/ivBigRecipeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:layout_toRightOf="#+id/ingredientsTitle"
android:background="#52D017"
android:contentDescription="food"
android:padding="1dp" />
in here are the pics
sometimes this happens:
and sometimes this happens:
Any ideas? I want to just have it exactly the actual size of it
thanks!
Try to add android:adjustViewBounds="true" to your ImageView, and it should work.
I am having two Images in two different ImageView and the Layout in LinearLayout and vertical orientation.
Now I want to Touch Frist image border(bottom part to) to other image's Top part . but in android by default it gives some space between them.
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
I want that , these Images touch each other. Thank you
try
android:layout_marginTop="-12dip"
in your second imageView
and 12dip change to your own num, notice that it is negative num.
and second way, use RelativeLayout can satisfied you.
Set android:padding to "0dp" and android:layout_marginTop/Bottom to "0dp" as well. Then there should be no reason they don't touch.
Also make sure your resources (png/jpg/etc) do not have extra transparency around the edges, as that will count towards the picture.