Aligned


Source link: https://github.com/Actinarium/Aligned

Aligned

Aligned is a tiny library for Android that makes putting text on baseline infinitely easier.

At the moment it does only one thing (and does it freaking rad!) — provides a TextView implementation that allows setting arbitrary leading and some other metrics on the text, helping you to place it nicely on the Material 8dp grid, pixel-perfect, cross-device¹, effortless!

How to use

First, add a dependency in your build.gradle, given that you have jcenter() in your repositories:

compile 'com.actinarium.aligned:aligned:0.1' 

For Maven and alternative configurations check Bintray page.

Now you can use com.actinarium.aligned.TextView in your layouts. It’s just like TextView, but offers three additional properties:

  • app:leading — forces the lines to have specified leading. You probably want to take the values from the spec;
  • app:firstLineLeading — allows to set special leading for the first line, otherwise app:leading will be used. You may want to use this instead of top margins.
  • app:lastLineDescent — specifies the distance from the baseline of the last line to the bottom of the view. Set this to a multiple of 4dp so that the bottom bound of the view also lands on the grid, and the next view is not misaligned.

<com.actinarium.aligned.TextView

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/label"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAppearance="@style/TextAppearance.AppCompat.Body1"

android:textSize="14sp"

app:leading="16sp"

app:firstLineLeading="24sp"

app:lastLineDescent="8sp" />

Tip: Since com.actinarium.aligned.TextView is a thin direct subclass of android.widget.TextView and both have the same short name, to avoid using full-qualified names you can just cast the view to TextView in your Java code unless you need the getters/setters for leading and descent properties:

import android.widget.TextView; // ... TextView myAlignedLabel = (TextView) findViewById(R.id.label);
 myAlignedLabel.setText(...);

Alternatively, you can use com.actinarium.aligned.Utils.setExactMetrics() method to programmatically adjust these properties of existing TextViews in your layouts.

License

The library is licensed under Apache 2.0 License, meaning that you can freely use it in any of your projects.

The full license text is here.

A personal appeal

If you already feel that this library is a godsend that will save you lots of time, please consider adding me on Google+ and/or Twitter. I am about to publish a free no-ads aesthetically awesome productivity app soon, and it will make me super-happy if you are one of the first to hear and try it out.

Also feel free to check Rhythm, my other typesetting adoration lib (psst, it’s used in the sample here to draw grids and bounds).


¹ — In case you find it to be not really cross-device, please open an issue.

Resources

This is a useful log tool for Android.

An enum based library to replace fragments, because #perfmatters.

View in circle shape that can be used as button with progress on long click. Also as static view to show progress or to simulate progress animation.

A pretty image picker for Android.

Monad on Android like Scala.

Very easy to use wrapper library for Android SharePreferences.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes