First thing, I know many people have asked same thing, but this one is nearly same but I have few more questions.
I have an image of 48px x 48px, so if I set this image in ImageView with
layout_width="wrap_content"
layout_height="wrap_content"
then image looks bigger but if I use following fixed size, it gets smaller
layout_width="48dp"
layout_height="48dp"
I think it's now showing properly(not pixelated ?) with 48dp, but why it got bigger if I use wrap_content ? And if the image size through wrap_content is correct then whats the point of using dp(if it make image smaller) ?
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling. To learn more about Drawables, see: Drawable Resources.
ImageButton has the same property as ImageView . Only one feature is extra, which is, images set through ImageButton are clickable, and actions can be attached with them upon clicking.
FIT CENTER (Default) If the asset is bigger than the ImageView , it is scaled down until both horizontal or vertical dimensions reach the edges of the ImageView . If the asset is smaller than the ImageView , it is scaled up until one of the horizontal or vertical dimensions reaches the edges of the ImageView .
48dp
(or 48dip
) stands for "Density Independent Pixel". This means that the physical size of the image as displayed on the screen of an Android should be the same regardless of screen density and size. In order to support this, Android adjusts the actual pixel size displayed based on screen density. Your findings of different sizes will vary from device to device.
The conversion of dp units to screen pixels is: pixels = dps * (density / 160)
. For example, on 240 dpi screen, 1dp
would equal 1.5 physical pixels. Using dp units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.
This probably happens because you don't explicitly set the scaleType. Set your scaleType in XML as follows and you should be fine:
android:scaleType="center"
Try this
<ImageView
android:id="@+id/seprator2"
layout_width="48dp"
layout_height="48dp"
android:scaleType="fitXY"
android:src="@drawable/your_image" />
And if still it shows small then your image must contains alpha around it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With