Android开源:Android Units - 一个显示单位转换的实用类
kim365
8年前
<h2>简介</h2> <p>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).</p> <p>In future iterations of this utility I would like to accommodate to above changes.</p> <h2>如何使用</h2> <p>Lets say you want to set the text size while drawing a custom view:</p> <pre> <code class="language-java">paint.setTextSize(AndroidUnits.SCALED_PIXELS.toPixels(8));</code></pre> <p>Or you want to draw a rectangle with rounded corners:</p> <pre> <code class="language-java">float radius = AndroidUnits.DENSITY_PIXELS.toPixels(12); canvas.drawRoundRect(rect, radius, radius, paint);</code></pre> <h2>下载</h2> <p>Add via Gradle:</p> <pre> <code class="language-java">allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { compile 'com.github.kevelbreh:androidunits:0.1.0' }</code></pre> <p>Or Maven:</p> <pre> <code class="language-xml"><repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependency> <groupId>com.github.kevelbreh</groupId> <artifactId>androidunits</artifactId> <version>0.1.0</version> </dependency></code></pre> <h2>许可</h2> <pre> <code class="language-java">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> <p> </p> <p> </p>