新聞中心
AttrHelper

創(chuàng)新互聯(lián)公司是由多位在大型網絡公司、廣告設計公司的優(yōu)秀設計人員和策劃人員組成的一個具有豐富經驗的團隊,其中包括網站策劃、網頁美工、網站程序員、網頁設計師、平面廣告設計師、網絡營銷人員及形象策劃。承接:網站建設、成都網站設計、網站改版、網頁設計制作、網站建設與維護、網絡推廣、數據庫開發(fā),以高性價比制作企業(yè)網站、行業(yè)門戶平臺等全方位的服務。
java.lang.Object
|---ohos.agp.components.AttrHelper
public class AttrHelper
extends Object
將屬性值的類型從字符串轉換為整數或布爾值。
構造函數摘要
| 構造函數 | 描述 |
|---|---|
| AttrHelper() | 用于創(chuàng)建 AttrHelper 實例的默認構造函數。 |
方法總結
| 修飾符和類型 | 方法 | 描述 |
|---|---|---|
| static int | convertDimensionToPix(String value, float density, int defaultValue) | 將尺寸值轉換為像素數。 |
| static int | convertDimensionToPix(Context context, String value, int defaultValue) | 將維度值轉換為像素值。 |
| static BlendMode | convertValueToBlendMode(String value, BlendMode defaultValue) | 將值從字符串轉換為整數。 |
| static boolean | convertValueToBoolean(String value, boolean defaultValue) | 將值從字符串轉換為布爾值。 |
| static Color | convertValueToColor(String value) | 將字符串轉換為 Color 對象。 |
| static ColorMatrix | convertValueToColorMatrix(int value) | 將值從 int 轉換為 ColorMatrix 對象。 |
| static Element | convertValueToElement(String value) | 將字符串轉換為 Element 對象。 |
| static float | convertValueToFloat(String value, float defaultValue) | 將字符串轉換為浮點值。 |
| static int | convertValueToInt(String value, int defaultValue) | 將值從字符串轉換為整數。 |
| static long | convertValueToLong(String value, long defaultValue) | 將字符串轉換為長值。 |
| static int | fp2px(float value, float density) | 根據屏幕密度將字體大小像素 (fp) 轉換為像素值。 |
| static int | fp2px(float value, float density, float fontRatio) | 根據屏幕密度和字體比率將字體大小像素 (fp) 值轉換為像素值。 |
| static int | fp2px(float value, Context context) | 根據屏幕上下文將字體大小像素 (fp) 轉換為像素值。 |
| static float | getDensity(Context context) | 獲取顯示密度。 |
| static float | getFontRatio(Context context) | 獲取字體比例。 |
| static float | px2fp(int value, Context context) | 根據屏幕上下文將像素轉換為字體大小的像素。 |
| static float | px2vp(int value, Context context) | 根據屏幕上下文將像素轉換為虛擬像素。 |
| static int | vp2px(float value, float density) | 根據屏幕密度將虛擬像素 (vp) 轉換為像素值。 |
| static int | vp2px(float value, Context context) | 根據屏幕上下文將虛擬像素 (vp) 轉換為像素值。 |
| 從類 java.lang.Object 繼承的方法 |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
構造函數詳細信息
AttrHelper
public AttrHelper()
用于創(chuàng)建 AttrHelper 實例的默認構造函數。
方法詳情
getDensity
public static float getDensity(Context context)
獲取顯示密度。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| context | 指示應用程序上下文。 |
返回:
返回顯示密度。
getFontRatio
public static float getFontRatio(Context context)
獲取字體比例。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| context | 指示應用程序上下文。 |
返回:
返回字體比例。
convertValueToInt
public static int convertValueToInt(String value, int defaultValue)
將值從字符串轉換為整數。
如果值為空,則返回 defaultValue 指定的值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 表示要轉換的值。 |
| defaultValue | 表示默認值。 |
返回:
返回轉換后的整數值。
convertValueToBlendMode
public static BlendMode convertValueToBlendMode(String value, BlendMode defaultValue)
將值從字符串轉換為整數。
如果值為空,則返回 defaultValue 指定的值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 表示要轉換的值。 |
| defaultValue | 表示默認值。 |
返回:
返回轉換后的 BlendMode 值。
convertValueToColorMatrix
public static ColorMatrix convertValueToColorMatrix(int value)
將值從 int 轉換為 ColorMatrix 對象。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 int 顏色值。 |
返回:
返回轉換后的 ColorMatrix 值。
convertValueToBoolean
public static boolean convertValueToBoolean(String value, boolean defaultValue)
將值從字符串轉換為布爾值。
確保布爾值是真或假。 否則會出現異常。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 表示要轉換的值。 |
| defaultValue | 表示默認值。 |
返回:
返回轉換后的布爾值。
convertValueToFloat
public static float convertValueToFloat(String value, float defaultValue)
將字符串轉換為浮點值。 如果字符串不存在,則返回defaultValue指定的值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 表示要轉換的字符串。 |
| defaultValue | 表示默認值。 |
返回:
返回轉換后的浮點值。
convertValueToLong
public static long convertValueToLong(String value, long defaultValue)
將字符串轉換為 long 值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 表示字符串值。 |
| defaultValue | 表示默認值。 |
返回:
轉換后返回 long 值。
convertValueToElement
public static Element convertValueToElement(String value)
將字符串轉換為 Element 對象。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的字符串。 |
回報:
返回元素對象。
convertValueToColor
public static Color convertValueToColor(String value)
將字符串轉換為 Color 對象。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的字符串。 |
返回:
返回顏色對象。
convertDimensionToPix
public static int convertDimensionToPix(String value, float density, int defaultValue)
將尺寸值轉換為像素數。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的尺寸值。 |
| density | 表示屏幕密度。 |
| defaultValue | 表示默認值。 |
返回:
返回轉換后的像素數。
convertDimensionToPix
public static int convertDimensionToPix(Context context, String value, int defaultValue)
將維度值轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| context | 指示應用程序上下文。 |
| value | 指示要轉換的尺寸值。 |
| defaultValue | 表示默認值。 |
返回:
返回一個像素值。
vp2px
public static int vp2px(float value, float density)
根據屏幕密度將虛擬像素 (vp) 轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 vp 值。 |
| density | 表示屏幕密度。 |
返回:
返回一個像素值。
vp2px
public static int vp2px(float value, Context context)
根據屏幕上下文將虛擬像素 (vp) 轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 vp 值。 |
| context | 指示屏幕上下文。 |
返回:
返回一個像素值。
fp2px
public static int fp2px(float value, float density)
根據屏幕密度將字體大小像素 (fp) 轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 fp 值。 |
| density | 表示屏幕密度。 |
返回:
返回一個像素值。
fp2px
public static int fp2px(float value, float density, float fontRatio)
根據屏幕密度和字體比率將字體大小像素 (fp) 值轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 fp 值。 |
| density | 表示屏幕密度。 |
| fontRatio | 表示字體比例。 |
返回:
返回一個像素值。
fp2px
public static int fp2px(float value, Context context)
根據屏幕上下文將字體大小像素 (fp) 轉換為像素值。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的 fp 值。 |
| context | 指示屏幕上下文。 |
返回:
返回一個像素值。
px2vp
public static float px2vp(int value, Context context)
根據屏幕上下文將像素轉換為虛擬像素。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的像素。 |
| context | 指示屏幕上下文。 |
返回:
返回一個虛擬像素。
px2fp
public static float px2fp(int value, Context context)
根據屏幕上下文將像素轉換為字體大小的像素。
參數:
| 參數名稱 | 參數描述 |
|---|---|
| value | 指示要轉換的像素。 |
| context | 指示屏幕上下文。 |
返回:
返回一個字體大小的像素。
新聞標題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSAttrHelper
當前鏈接:http://m.5511xx.com/article/dpiojpd.html


咨詢
建站咨詢
