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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
17 views

Android get Touch Position on a remote device and reflect the same position on server screen

Good wishes to all. I am having a situation where I have a streaming server,That runs a video (width = 1260, height = 690). I get this Url and play it in a WebView with random size (as of Android ...
  • 1
0 votes
0 answers
34 views

how to change th value of layout in MainActivity.java?

i am using android studio in x.xml, i set the layout_height=400dp <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="wrap_content" android:...
  • 11
0 votes
1 answer
25 views

How can I know the pixels range for all screen densities in Android ? (base density of an image)

So imagine that I have an image that is 700x700 px in res folder and I want my app to support different pixel densities. So according to the documentation: ldpi -- 0.75x mdpi -- 1x hdpi -- 1.5x xhdpi -...
0 votes
1 answer
21 views

Formula to convert any dpi to any dpi

I need the formulas to calculate any dpi to any dpi. For example: mdpi to hdpi, xdpi to xxhdpi, etc. This website exactly does what I require but I am not able to find the logic for it. Any ...
  • 937
0 votes
0 answers
67 views

calculus of dp and actual dp doesn't match

i calculated the dp of a device (smallest width), in particular a google pixel 3 (440dpi 1080x2160), using the formula: px = dp*(dpi/160) the result was 392.72, so i created the file animator-sw390dp-...
  • 127
0 votes
0 answers
114 views

How can I determine the dimens of each screen? - Android studio

I am new to programming and I didn't quite understand the dimens, I know there are small, normal, large and xlarge screen sizes. I also know the densities: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi. I ...
9 votes
2 answers
2k views

Android Compose set height of view in pixels NOT in dp

I want to set the height of view in pixels not in dp. `Box(modifier = Modifier.height(100.dp))` In this example height of the box is set to 100 dp and modifier function accepts only dp. How to set ...
1 vote
1 answer
219 views

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 ...
  • 1,137
0 votes
0 answers
67 views

Text is stretched on different screen in my custom view after settings text size in dp android

I am trying to create a text sticker in android. I am creating a text sticker on one of my phones and then saving the text size in the DP. Then on another phone, I am loading the same text with the ...
1 vote
0 answers
130 views

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 ...
  • 38.9k
1 vote
0 answers
51 views

Negative margin on different devices

Source code can be found at : https://github.com/AliRezaeiii/Contacts I have following layout in my Activity : <?xml version="1.0" encoding="utf-8"?> <androidx....
  • 9,588
1 vote
0 answers
29 views

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 ...
  • 137
0 votes
3 answers
1k views

Android add a padding with size that looks equal on all devices

I have a view that is the same size as my screen / fragment. However, I want to add a padding on the left and right edges such that on all devices, this padding looks like its the same size. when I ...
  • 1,871
1 vote
1 answer
2k views

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 ...
7 votes
4 answers
1k views

Is ConstraintSet.connect() margin parameter in px or dp?

val margin = 8 ConstraintSet().apply { connect(anId, ConstraintSet.START, anotherId, ConstraintSet.START, margin) } Is margin applied as pixels or density-dependent pixels? Various articles ...
  • 1,274
1 vote
5 answers
870 views

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....
-2 votes
1 answer
131 views

How to call image variable to another call in c#

I have two class Mainwindow and Mini_Screen which derive from Window class.i want to access image variable to another class and how video stream.here is the code public partial class MainWindow : ...
1 vote
1 answer
27 views

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 ...
3 votes
1 answer
1k views

HorizontalOffset goes in the wrong direction for High DPI primary screen

I am currently working on some high DPI issues in our WPF app (.NET 4.6.1 - System DPI-awareness is active). Generally the app does what we expect it to do - scale depending on the current displays ...
1 vote
1 answer
172 views

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 (...
  • 13
0 votes
2 answers
3k views

How to build UI that support all screen sizes and devices in android

I'm currently trying to develop an android application but I've been stuck for a while now trying to scale the views in an activity. In the picture you can see that the resolution-width is 10px(It's ...
  • 57
0 votes
2 answers
678 views

Android TextView decimal size issue

I tested emulators and real devices but as you can see there is no change between 40 dp and 40.2 dp! I'm working on a project with a very high font sensitivity and the issue is behaviour of android ...
-1 votes
1 answer
3k views

can't find dimens.xml file. how to create one? [closed]

I want to have a dimens.xml file, where I keep dimensions that I use in my Android Studio main_activity.xml file, but I can't find it in app->res->values. Are we supposed to create that file on our ...
  • 9
-7 votes
1 answer
2k views

Android layout does not fit in screen

I have a layout that fits all of the phones but when the resolution is 480x800 the bottom of the layout is off the screen. I am using dpsizes. Should not it be density independent regardless of the ...
  • 385
0 votes
1 answer
91 views

Same view size on all screens

I need to display view with exact size in milimeters. The problem I face is that on many android devices when i apply view size im mm, the output differs. Is there any way to achieve the exact same ...
  • 73
1 vote
0 answers
224 views

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 ...
  • 268
12 votes
4 answers
13k views

How to convert dp to px in xamarin.android?

I want to convert dp to px in my C# code in xamarin.android, but all I could find were java codes in android studio that have some problems in xamarin. I tried to use equivalent like using Resources ...
3 votes
0 answers
825 views

javafx how to achieve density independent design

 Hello all,                 We are trying to achieve Density Independent Design in javaFX.(say if window width of ...
  • 1,434
2 votes
1 answer
203 views

Use dp width in PercentRelativeLayout

When I try to add a view without "widthPercent" or "heightPercent" in a PercentRelativeLayout, the view doesn't show up. The reason why I want this is to add a divider between the 2 elements of my ...
  • 5,298
0 votes
1 answer
23 views

How can i support different measurements for screens in android

I basically want to accomplish an adequate size of my layouts depending on the screen size of the device. I am using dp as unit, but it doesn't seem to work. How can i do that?
user avatar
0 votes
1 answer
125 views

How to assign values to image array in Matlab?

I am trying to write a matlab code which copies one segment of an image into another with a particular range matrices. My code works as required. The only problem I am having is that I want to assign ...
0 votes
1 answer
155 views

One coordinate grid for all Android device (Appcelerator)

Currently I'm using percentages to maintain my Android app UI, but I think this is'nt the best solution. I found this in the documentation: The coordinates grid Titanium uses a grid coordinate ...
  • 43
2 votes
3 answers
300 views

TextView is on different heights on different resolutions. DIP doesn't work

The bottom property of below textView scales wrong, the TextView is on a different height on every Android device: See attached pictures. public class MainActivity extends Activity { @Override ...
1 vote
0 answers
229 views

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 ...
user avatar
0 votes
1 answer
45 views

Screen resolution with images issue

I've been working on an app for a little while now that creates a tile puzzle. I'm to the point where I'm testing for various size and density screens. Using Krita I scaled the tile images down to ...
0 votes
1 answer
544 views

how to sharp an image thumbnail in java?

I have created a thumbnail image in java using imgscalr library and thumbnail created with good quality but i want to sharpen that thumbnail. so please help me to sharpen thumbnail image.
0 votes
0 answers
91 views

How do I visualise dip unit for HDPI screen?

For a 160dpi (MDPI) screen, 1dip is 1px, as shown below, For a 320dpi (XHDPI) screen, 1dip is 2px, as shown below, For a 240dpi (HDPI) screen, 1dip is 1.5px, But, How do I visualise 1dip in pixels ...
  • 15.1k
2 votes
3 answers
1k views

How to compute device independent pixel units?

I am assuming that the terminology Density-independent pixels and Device-independent pixels, have same meaning. Density-independent pixels(dip) are a virtual pixel unit, equivalent to one physical ...
  • 15.1k
0 votes
1 answer
118 views

Android - Puzzles about conversion between dp and pixel

I know this might be a silly question but I have really gone through so many materiel and links but still not quite understand it. In the "Supporting Multiple Screens" section of Android ...
  • 123
3 votes
2 answers
1k views

How to get width and height of resized custom view , before it is drawn

In my custom View .xml , i have defined width and height as w = 600dp , h = 700dp. Now i know getMeasuredHeight() / getMeasuredWidth() give values of width and height after view is drawn and they may ...
1 vote
2 answers
735 views

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 ...
  • 1,032
1 vote
1 answer
396 views

opencv real time video frame does not showing sobel output in android

I am new to opencv. I want to apply sobel filter on real time video using opencv in android but i am failed in doing so. when i use the built-in function of sobel in opencv it gives me the white blank ...
  • 95
2 votes
4 answers
711 views

How to implement DIP in an MVC environment?

Dependency Inversion Principle states that higher level modules should not depend on lower level modules. Both should depend on abstractions. I do understand that principle. But as I'm using ASP.NET ...
97 votes
7 answers
86k views

How to convert DP, PX, SP among each other, especially DP and SP?

I have known the difference among DP, SP and PX. And after searching this topic, I found nothing satisfying me completely. Maybe this post is a duplicate, but I still want to know what is the formula ...
  • 13.6k
2 votes
0 answers
1k views

Using Canvas to draw rectangles to fit in a specified width screen

Using the code given below we can retrieve the height and the width of a particular screen size : DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); float ...
0 votes
0 answers
31 views

Android harmony pixels

i will explain my problem with an image ! I draw a figure with my finger and at the same time coordinates is sent to clients.As you understand i am working with hard coded pixels.Algorithm is simple ...
  • 55
0 votes
0 answers
67 views

Am I adding layouts correctly?

After doing my prior research on the top 10 handsets and tablets in my country, I can classify them as follows: HANDSETS: 533dp x 320dp 640dp x 360dp 853dp x 480dp TABLETS: 1280dp x 800dp 960dp ...
  • 24.5k
5 votes
3 answers
3k views

How to find what density bucket the phone is in?

Slightly noob-ish question but I get confused when it comes to calculating what density bucket the phone falls in. I'll take my Galaxy S3 as an example. It has a resolution of 1280 x 720 which ...
  • 24.5k
0 votes
1 answer
716 views

Android Actionbar Icon Drawable

As you probably know, there are some icons on Github from Google to use. I wanted to implement a actionbar icon and saw this here(google.com/design) and this(dev.android.com). google.com/design tells ...
-2 votes
2 answers
1k views

How to set BMP file width and height in DIB header when image size exceeds 255 pixels?

I am creating simple BMP image with Java. Unfortunately I do not know how to store width and height size information into the DIB header, when the size of width or height exceeds 255 value in decimals ...
  • 89