android-R.dimen

R.dimen

public static final class R.dimen 
extends Object 

java.lang.Object
   ↳ android.R.dimen


Summary


Constants

int app_icon_size

The standard size (both width and height) of an application icon that will be displayed in the app launcher and elsewhere.

int dialog_min_width_major

The platform's desired minimum size for a dialog's width when it is along the major axis (that is the screen is landscape).

int dialog_min_width_minor

The platform's desired minimum size for a dialog's width when it is along the minor axis (that is the screen is portrait).

int notification_large_icon_height

The width of the big icons in notifications.

int notification_large_icon_width

The width of the big icons in notifications.

int thumbnail_height

The height that is used when creating thumbnails of applications.

int thumbnail_width

The width that is used when creating thumbnails of applications.

Public constructors

R.dimen()

Inherited methods

From class java.lang.Object

Constants


app_icon_size

Added in  API level 1
int app_icon_size

The standard size (both width and height) of an application icon that will be displayed in the app launcher and elsewhere.

Constant Value: 17104896 (0x01050000)

dialog_min_width_major

Added in  API level 11
int dialog_min_width_major

The platform's desired minimum size for a dialog's width when it is along the major axis (that is the screen is landscape). This may be either a fraction or a dimension.

Constant Value: 17104899 (0x01050003)

dialog_min_width_minor

Added in  API level 11
int dialog_min_width_minor

The platform's desired minimum size for a dialog's width when it is along the minor axis (that is the screen is portrait). This may be either a fraction or a dimension.

Constant Value: 17104900 (0x01050004)

notification_large_icon_height

Added in  API level 11
int notification_large_icon_height

The width of the big icons in notifications.

Constant Value: 17104902 (0x01050006)

notification_large_icon_width

Added in  API level 11
int notification_large_icon_width

The width of the big icons in notifications.

Constant Value: 17104901 (0x01050005)

thumbnail_height

Added in  API level 1
int thumbnail_height

The height that is used when creating thumbnails of applications. The height that is used when creating thumbnails of applications. The height that is used when creating thumbnails of applications.

Constant Value: 17104897 (0x01050001)

thumbnail_width

Added in  API level 1
int thumbnail_width

The width that is used when creating thumbnails of applications. The width that is used when creating thumbnails of applications. The width that is used when creating thumbnails of applications.

Constant Value: 17104898 (0x01050002)

Dimension型资源

定义在XML中的尺寸值。它是一个带有尺寸单位的数字。例如:10px2in5sp。以下是Android系统支持的尺寸单位:

dp

密度无关的像素,它是基于屏幕的物理密度的一种抽象单位。相对与160dpi(每英寸的点数)的屏幕,每1dp大致等于1px。当运行在高密度的屏幕上时,用于描画1dp的像素数会适应屏幕的dpi的要求来进行放大。同样,当在低密度屏幕上时,1dp的像素也会被缩小。从dppixel的转换比率会随着屏幕的密度来改变,但是不一定成正比。使用dp作为单位(代替px单位)是一个中简单的解决方案,它会让布局中View对象针对不同的屏幕密度来进行正确的调整。换句话说,它提供了UI元素的实际尺寸在不同设备上的一致性。

sp

尺寸无关的像素,它有点像dp单位,但是它也会根据用户的字体尺寸选择来进行缩放。它被推荐用于指定字体的尺寸,以便文字能够针对屏幕的密度和用户的选择来调整。

pt

点数,基于屏幕的物理尺寸,确定1/72英寸中的点数。

px

像素,跟屏幕上的实际像素相对应。不推荐使用这个尺寸单位,因为实际上要适应各种不同的设备,每个设备每英寸的像素数量都可能不同,并且屏幕上可能会有更多或更少的总的可用的像素。

mm

毫米,基于屏幕的物理尺寸。

in

英寸,基于屏幕的物理尺寸。

注意:尺寸资源是一种简单的资源,可以使用其name属性提供的值来引用这种资源。如,能够把尺寸资源跟其他简单资源组合在一个XML文件的<resources>元素中。

文件位置(FILE LOCATION):

res/values/filename.xml

文件名是任意的,<dimen>元素的name属性值会被用于资源ID

资源引用(RESOURCE REFERENCE):

Java代码中:R.dimen.dimension_name

XML中:@[package:]dimen/dimension_name

语法(SYNTAX):

 <?xml version="1.0" encoding="utf-8"?>
<resources>
    
<dimen
        
name="dimension_name"
        
>dimension</dimen>
</resources>

元素(ELEMENTS):

<resources>

必须的,它必须是根节点。没有属性。

<dimen>

它定义一个尺寸值,用带有尺寸单位(dpspptpxmmin)的浮点数来表示。

属性(ATTRIBUTES):

name

字符串值,它定义了这个尺寸的名称,属性值被用作资源的ID

例子(EXAMPLE):

下面的XML保存在res/values/dimens.xml中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    
<dimen name="textview_height">25dp</dimen>
    
<dimen name="textview_width">150dp</dimen>
    
<dimen name="ball_radius">30dp</dimen>
    
<dimen name="font_size">16sp</dimen>
</resources>

以下是应用程序代码获取尺寸资源的方法:

Resources res = getResources();
float fontSize = res.getDimension(R.dimen.font_size);

以下是在布局XML中设置尺寸属性的方法:

<TextView
    
android:layout_height="@dimen/textview_height"
    
android:layout_width="@dimen/textview_width"
    
android:textSize="@dimen/font_size"/>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值