android - Trying to create an EditText with a Label without the label being moved -
i'm trying create edittext has label inside edittext , i've been using sec suggestion of accepted reply here.
i've managed sort of working, few problems. here's how looks:
that's fine, until seek , come in text. there no margin between label , entered text:
also, label cannot removed backspace, disappear when come in plenty text force off left:
here code custom edittext - same in thread mentioned above:
public class kingdomspasedittext extends edittext { private int paddingleft; private string label = ""; public kingdomspasedittext(context context) { super(context); paddingleft = getpaddingleft(); } public kingdomspasedittext(context context, attributeset attrs) { super(context, attrs); paddingleft = getpaddingleft(); label = attrs.getattributevalue("http://www.kingdomspas.com/android/custom", "label"); if (label == null) { label = ""; } } protected void ondraw(canvas canvas) { textpaint textpaint = getpaint(); rect size = new rect(); textpaint.gettextbounds(label, 0, label.length(), size); setpadding(paddingleft + size.width(), getpaddingtop(), getpaddingright(), getpaddingbottom()); super.ondraw(canvas); canvas.drawtext(label, paddingleft + size.left, size.bottom + getpaddingtop() + 50, textpaint); } protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); } } you may notice in drawtext() adding 50 top padding. if don't looks this:
this seems hack me.
here xml used create each edittext - difference beingness label. both in tablerow is, obviously, part of tablelayout:
<com.kingdomspas.android.kingdomspasforms.formfields.kingdomspasedittext android:id="@+id/edittext1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxlines="1" android:singleline="true" android:background="@drawable/round" android:paddingtop="2dp" android:paddingleft="8dp" android:layout_weight="1" kingdomspas:label="test text 1: "> <requestfocus /> </com.kingdomspas.android.kingdomspasforms.formfields.kingdomspasedittext> ok, sticking me. here summary of problems:
1) how can create margin between label , entered text? 2) how can prevent label disapearing of right? 3) there improve way of label in edittext
android android-layout
No comments:
Post a Comment