简体   繁体   English

在自定义按钮视图中更改宽度/高度值

[英]Change width/height value in custom button view

Is there any way that i can change the value of android:layout_width/height in an implement of custom button? 有什么办法可以在自定义按钮的实现中更改android:layout_width / height的值? (I want to insert something like that: android:layout_width="50dp,100dp" ) (我想插入类似的内容: android:layout_width =“ 50dp,100dp”

You can't. 你不能 android:layout_width and android:layout_height parameters need to be specified for any and all views. android:layout_widthandroid:layout_height参数需要的任何和所有的意见进行指定。 No exceptions. 没有例外。

Along the ones you mentioned, you may use any of these values as an attribute 沿着您提到的值,您可以将这些值中的任何一个用作属性

  • Density-independent Pixels (dp) - An abstract unit that is based on the physical density of the screen. 密度无关像素(dp) -基于屏幕物理密度的抽象单位。 These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. 这些单位相对于160 dpi(每英寸的点数)屏幕,在该屏幕上1dp大致等于1px。 When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. 在更高密度的屏幕上运行时,用于绘制1dp的像素数量会按适合屏幕dpi的系数放大。 Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. 同样,在较低密度的屏幕上,用于1dp的像素数会按比例缩小。 The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. dp与像素的比率将随屏幕密度而变化,但不一定成正比。 Using dp units (instead of px units) is a simple solution to making the view dimensions in your layout resize properly for different screen densities. 使用dp单位(而不是px单位)是一种简单的解决方案,可以针对不同的屏幕密度正确调整布局中的视图尺寸。 In other words, it provides consistency for the real-world sizes of your UI elements across different devices. 换句话说,它为跨不同设备的UI元素的实际大小提供了一致性。
  • Scale-independent Pixels (sp) - This is like the dp unit, but it is also scaled by the user's font size preference. 与比例无关的像素(sp) -类似于dp单位,但也通过用户的字体大小首选项进行缩放。 It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference. 建议您在指定字体大小时使用本机,以便针对屏幕密度和用户的喜好进行调整。
  • Points(pt) - 1/72 of an inch based on the physical size of the screen. 点数(pt) -基于屏幕的物理尺寸的1/72英寸。 px 像素
  • Pixels(px) - Corresponds to actual pixels on the screen. 像素(px) -对应于屏幕上的实际像素。 This unit of measure is not recommended because the actual representation can vary across devices; 不建议使用此度量单位,因为实际的表示可能会因设备而异。 each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen. 每个设备每英寸可能具有不同数量的像素,并且屏幕上可用的总像素可能更多或更少。 mm 毫米
  • Millimeters(mm) - Based on the physical size of the screen. 毫米(mm) -基于屏幕的物理尺寸。 in Inches - Based on the physical size of the screen 英寸-基于屏幕的物理尺寸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM