Last active
August 29, 2015 14:06
-
-
Save malmstein/a31113ca820a31ed2a24 to your computer and use it in GitHub Desktop.
custom layout attribute loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<declare-styleable name="FloatLabelLayout"> | |
<attr name="floatLabelTextAppearance" format="reference" /> | |
<attr name="floatLabelSidePadding" format="reference|dimension" /> | |
</declare-styleable> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class FloatLabelLayout extends FrameLayout { | |
private static final long ANIMATION_DURATION = 150; | |
private static final float DEFAULT_PADDING_LEFT_RIGHT_DP = 12f; | |
private EditText mEditText; | |
private TextView mLabel; | |
public FloatLabelLayout(Context context) { | |
this(context, null); | |
} | |
public FloatLabelLayout(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
final TypedArray a = context | |
.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout); | |
final int sidePadding = a.getDimensionPixelSize( | |
R.styleable.FloatLabelLayout_floatLabelSidePadding, | |
dipsToPix(DEFAULT_PADDING_LEFT_RIGHT_DP)); | |
mLabel = new TextView(context); | |
mLabel.setPadding(sidePadding, 0, sidePadding, 0); | |
mLabel.setVisibility(INVISIBLE); | |
mLabel.setTextAppearance(context, | |
a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance, | |
android.R.style.TextAppearance_Small)); | |
addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); | |
a.recycle(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<com.novoda.dch.view.FloatLabelLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:floatLabelTextAppearance="@style/dch_FloatLabel"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment