density-independent-pixel

How to convert dp to px in xamarin.android?

时间秒杀一切 提交于 2019-12-23 07:27:33
问题 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 instead of getResources() and I could solve some little problems, but there are some problems yet that I couldn't find any equivalent for them. here are original codes, my codes, and my codes problems in xamarin: First code (found from Programatically set height on LayoutParams as density

Two screens with the same dimensions but different resolutions

独自空忆成欢 提交于 2019-12-20 05:16:08
问题 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 only difference will be the crispness of the views. 回答1: If the screens are the same physical dimension but have a differing dpi and you've used the dp (Density-independent pixel) then they should be the same as this is the point of the dp unit. This

Does setWidth(int pixels) use dip or px?

自闭症网瘾萝莉.ら 提交于 2019-12-17 06:22:16
问题 Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example, does setWidth(100) set the a view's width to 100 dips or 100 pxs? Thanks. 回答1: It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is in TypedValue.applyDimension(). Here's an example of how to convert dips to px in code: // Converts 14 dip into its equivalent px Resources r = getResources(); int px = Math.round(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 14

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

↘锁芯ラ 提交于 2019-12-13 19:43:11
问题 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 differ from what i've given in .xml file , is there a workaround to get getMeasuredHeight() and getMeasuredWidth() values before view is actually drawn on layout, without use of onMeasure() ? And How to calculate changed dp sizes in different screens ? like my 600h*700w when run on emulator

Android views not scaling on different sized devices

纵然是瞬间 提交于 2019-12-11 23:24:00
问题 I am using eclipse I have views with images and buttons with their width and height set in dp: <Button android:id="@+id/btn_menu_games" android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center" android:background="@drawable/ico_games" android:onClick="goToGames" /> But when I use a different device the images and buttons do not scale relative to the screen, so they are really big on a small screen and really small on a big screen. Am I doing something wrong in

Issue with DP calculation on 7“ tablet & 7” tablet emulator

醉酒当歌 提交于 2019-12-07 22:55:06
问题 I am having some problems with the dp calculation for a 7" tablet (800x480px). Below is my way of calculating. Can't find where I am making a mistake in calculation or my thought: I have three devices that I'm testing: Nexus One: 800x480px, 3.7" display (specs) Huawei Ideos: 320x240px, 2.8" display (specs) Ainol Novo 7" Tablet: 800x480px, 7" display (specs) Based on the display size, I'm calculating the DPI (dots per inch) manually, based on the formular: sqrt(w^2 + h^2) / in So I am getting:

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

时光怂恿深爱的人放手 提交于 2019-12-06 13:00:43
问题 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 with landscape-mode, tested it mainly on my own personal Droid phone, and basically felt like I was only developing for my own device. Although I did always use dpi and sp in the appropriate places, this was not enough for my app to scale

WPF Units and Code-Behind

 ̄綄美尐妖づ 提交于 2019-12-05 12:32:09
问题 Recently I discovered WPF supports different measurement units in XAML. Besides default DIPs, there is also support for pixels, inches and centimeters (as far as I know). This allows designer to write XAML such as this: <Canvas> <Line X1="0cm" X2="3cm" Y1="1cm" Y2="3cm" Stroke="Black"/> </Canvas> However, you cannot bind these values. Imagine we have a ViewModel with Dimension property which is a String, for example "7cm". Following won't work: <Button Width="{Binding Dimension}">Test</Button

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

陌路散爱 提交于 2019-12-04 19:14:20
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 with landscape-mode, tested it mainly on my own personal Droid phone, and basically felt like I was only developing for my own device. Although I did always use dpi and sp in the appropriate places, this was not enough for my app to scale appropriately on other screen sizes/densities. It scaled okay sometimes, but would always tend to cut off a