Questions tagged [density-independent-pixel]

DIP is short for Density Independent Pixel. It is used by the Android system as a unit of measurement to make GUIs fit on different screen sizes with scaling. This allows the developer to create a single interface for different screen sizes.

119 questions
1
vote
2 answers

Why displayMetrics.density is wrong?

On my Pixel 7 device, I want to know how many density-independent pixels (dp) I have. So, I use this formula: displayMetrics.widthPixels / displayMetrics.density However, I have an issue because displayMetrics.widthPixels = 1080 (which is okay) and…
zeus
  • 12,173
  • 9
  • 63
  • 184
1
vote
1 answer

React-Native: Text is rendering differently in different mobile phones

This is the style I ma using to render Text TEXT_B16: { fontFamily: 'OpenSans-Bold', fontWeight: fontWeight, fontSize: 16, lineHeight: 22, }, And output is as follows, Samsung One plus iPhone 12 Pro Max iPhone 6 even though…
ThinkAndCode
  • 1,319
  • 3
  • 29
  • 60
1
vote
1 answer

Changing Transparent Background to White in Matlab

Please consider the following piece of Matlab code: MyImage = imread('a.png'); imwrite(MyImage, 'a.jpg', 'jpg'); The problem I am facing is that a.png has a transparent background. When I save it as jpg, it saves the image with black…
Haider
  • 938
  • 2
  • 11
  • 25
1
vote
0 answers

is galaxy s10 (xxxhdpi) scaled 4x or 3.5x?

https://material.io/resources/devices/ (which is not maintained anymore) has 3.5x for xxxhdpi google pixel xl 4x for xxxhdpi galaxy s8 https://material.io/blog/device-metrics lists only 4x for xxxhdpi https://reactnative.dev/docs/pixelratio lists…
eugene
  • 39,839
  • 68
  • 255
  • 489
1
vote
0 answers

Negative margin on different devices

Source code can be found at : https://github.com/AliRezaeiii/Contacts I have following layout in my Activity :
Ali
  • 9,800
  • 19
  • 72
  • 152
1
vote
0 answers

Difference in items height at layouts with same DP value

I am running 2 emulators: 360x640 mdpi (1x) 1080x1920 xxhdpi (3x) Using dp values when defining attributes for views should result in covering same physical space, but as the result they look different. What might be the reason for such outcome?
1
vote
1 answer

How to set text size depending on the screen dimensions?

I need to set all the text content of the application depending on the screen dimensions. I mean buttons, textviews etc... For example, If i execute the app ina Pixel C tablet, the buttons text size and the textviews text size must be very big, and…
1
vote
5 answers

Same text size but it larger on other devices

I have a TextView in which I programmatically setup the text size in 'SP'. tv.setTextSize(spToPx(5, context)); public static int spToPx(float sp, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,…
1
vote
1 answer

Scaling drawables not to density (dip), but actual pixel resolution (px)

I've been working on an app where it is important that drawables are always the same size relative to the display's width, e.g. always 1/8 of the screen height in pixels. I understand how density independent pixels work, but as their goal is to…
1
vote
1 answer

Dp in xml doesn't match java dp-px conversion

I need to set sizes of text, margins or images in java rather than in xml due to loop repetition. When I set 20dp for text in xml file, result is 3x smaller than same 20dp converted to px with this (Material design guide based) conversion method: dp…
Govean
  • 13
  • 2
1
vote
1 answer

How do you begin developing an Android app for multiple devices sizes/densities?

I've asked a question similar to this but thought I would ask a more general question to get a wider range of input. I ask this question because the last two apps I've developed, I threw all image resources in the drawable-hdpi folder, didn't deal…
joepetrakovich
  • 1,344
  • 3
  • 24
  • 42
1
vote
2 answers

Android DIP size wrong

This one is bedeviling me. What am I overlooking? I want a button exactly one inch wide, on any density screen. I declare it in the layout like this:
1
vote
0 answers

Pixel data changes after writing to JPEG file

I am performing steganography on JPEG images. I am using DCT coefficients to hide data. I do the following steps: Read input image into BufferedImage Get an 8 x 8 block from BufferedImage Apply forward DCT to get DCT coefficients Embed message bits…
1
vote
0 answers

Device Independent Pixel Scaling In Browser

I was following a video tutorial and it stated that the browser in a chromebook has a viewport width of 1280 DIPS and in this case they stated that the 1280 DIPS will be scaled up to the 2560 hardware pixels of the chromebook when the page is…
user5228393
1
vote
2 answers

Two screens with the same dimensions but different resolutions

Assume we have two android devices with the same screen dimensions, but with different resolutions. Is the following true or not: if dp unit is used to set the sizes of all views, then both screens will display the same amount of contents and the…
boring91
  • 1,051
  • 12
  • 28