Android開源:Android Units - 一個顯示單位轉換的實用類

kim365 7年前發布 | 8K 次閱讀 移動開發 Android開發

簡介

A utility class for converting between different Android display units without requiring an application context. This uses the system global shared Resources object and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

In future iterations of this utility I would like to accommodate to above changes.

如何使用

Lets say you want to set the text size while drawing a custom view:

paint.setTextSize(AndroidUnits.SCALED_PIXELS.toPixels(8));

Or you want to draw a rectangle with rounded corners:

float radius = AndroidUnits.DENSITY_PIXELS.toPixels(12);
canvas.drawRoundRect(rect, radius, radius, paint);

下載

Add via Gradle:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
  compile 'com.github.kevelbreh:androidunits:0.1.0'
}

Or Maven:

<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url&gt;
  </repository>
</repositories>

<dependency> <groupId>com.github.kevelbreh</groupId> <artifactId>androidunits</artifactId> <version>0.1.0</version> </dependency></code></pre>

許可

Copyright 2017 Kevin Woodland

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</code></pre>

 

 

 本文由用戶 kim365 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!