Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IanGClifton/AndroidFloatLabel
Library project with a custom view that implements the Float Label pattern
https://github.com/IanGClifton/AndroidFloatLabel
Last synced: about 6 hours ago
JSON representation
Library project with a custom view that implements the Float Label pattern
- Host: GitHub
- URL: https://github.com/IanGClifton/AndroidFloatLabel
- Owner: IanGClifton
- License: apache-2.0
- Created: 2013-12-31T07:08:43.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-23T01:46:52.000Z (over 9 years ago)
- Last Synced: 2023-11-07T15:24:40.436Z (about 1 year ago)
- Language: Java
- Size: 1.07 MB
- Stars: 471
- Watchers: 29
- Forks: 93
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-android-ui - https://github.com/IanGClifton/AndroidFloatLabel
- awesome-android-ui - https://github.com/IanGClifton/AndroidFloatLabel
README
AndroidFloatLabel
=================This repository contains an Android library project for Android 4.0+ with a custom view that implements the Float Label pattern (http://dribbble.com/shots/1254439--GIF-Float-Label-Form-Interaction) and an example project using the Float Label library. The custom View, FloatLabel, basically consists of two pieces: the EditText and the label (a TextView).
Quick Overview
--------------- [YouTube demo](http://www.youtube.com/watch?v=9VoVxw8aAx0)
- [Google Play example app](https://play.google.com/store/apps/details?id=com.iangclifton.android.floatlabelexample)Getting Started
---------------Download the source to use it as a library project or use it directly from Maven Central in your dependencies. For example:
dependencies {
compile 'com.iangclifton.android:floatlabel:1.0.4'
}For most use, you can simply use the custom view in your XML layout, specifying a label to use as both the EditText hint and the label TextView with the
android:hint
property. Example:
You can also dynamically set the label with
floatLabel.setLabel("Custom Label")
orfloatLabel.setLabel(R.string.custom_label)
. You can dynamically set the text of the EditText withfloatLabel.setText()
. All the typical setText variations are supported. If you want to set the text without an animation (such as if you're programmatically preparing views in onCreate), usefloatLabel.setTextWithoutAnimation()
(again, all the usual variations are supported).If you need a reference to the EditText, you can call
floatLabel.getEditText()
.Custom Layout
-------------If you want to specify a custom layout to use, you can do something like this:
Your custom layout should include a label TextView (
id/float_label
) and an EditText (id/edit_text
). The custom layouts are extremely limited because the FloatLabel simply lays out the label and the EditText and ignores all other views. This is very efficient but also prevents you from creating a much more complex layout. Here's an example:
Custom Animation
----------------You can override the animations used to show and hide the label by implementing a
FloatLabel.LabelAnimator
and callingfloatLabel.setLabelAnimator(new MyLabelAnimator());
. Note that you should use the alpha property of the label to show and hide it rather than the View.setVisibility(int) method. Example:private static class CustomLabelAnimator implements FloatLabel.LabelAnimator {
/*package*/ static final float SCALE_X_SHOWN = 1f;
/*package*/ static final float SCALE_X_HIDDEN = 2f;
/*package*/ static final float SCALE_Y_SHOWN = 1f;
/*package*/ static final float SCALE_Y_HIDDEN = 0f;@Override
public void onDisplayLabel(View label) {
final float shift = label.getWidth() / 2;
label.setScaleX(SCALE_X_HIDDEN);
label.setScaleY(SCALE_Y_HIDDEN);
label.setX(shift);
label.animate().alpha(1).scaleX(SCALE_X_SHOWN).scaleY(SCALE_Y_SHOWN).x(0f);
}@Override
public void onHideLabel(View label) {
final float shift = label.getWidth() / 2;
label.setScaleX(SCALE_X_SHOWN);
label.setScaleY(SCALE_Y_SHOWN);
label.setX(0f);
label.animate().alpha(0).scaleX(SCALE_X_HIDDEN).scaleY(SCALE_Y_HIDDEN).x(shift);
}
}Related Projects
----------------* [Fork of Float Label for Android 2.3+](https://github.com/edouardouvrard/AndroidFloatLabel-API9)