android - TextView inside EditText align -
some days ago searching edittext implementation "label" inside username input. found following xml code stackoverflow.
<framelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <edittext android:id="@+id/username_edittext" android:layout_width="match_parent" android:layout_height="wrap_content" android:textsize="15sp" android:hint="Πατήστε εδώ" android:inputtype="text" android:maxlength="20" android:paddingleft="125dp" tools:ignore="hardcodedtext" > <requestfocus /> </edittext> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginbottom="0dp" android:layout_marginleft="0dp" android:layout_marginright="0dp" android:paddingleft="12dp" android:text="Όνομα χρήστη:" android:textcolor="@color/grey" android:textsize="15sp" tools:ignore="hardcodedtext" /> </framelayout>
the result needed,except 1 thing.both edittext , textview not align in y axis,the bottom of text not aligned in small resolutions.the screenshot got 3.7 inches:
i draw red line can see not align. help?
to align text, need relativelayout layout parameter: android:layout_alignbaseline component. try , keep me updating:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativelayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" > <edittext android:id="@+id/username_edittext" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:inputtype="text" android:ems="10" android:maxlength="20" android:textsize="15sp" android:hint="Πατήστε εδώ" android:paddingleft="125dp" > <requestfocus /> </edittext> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/username_edittext" android:layout_alignbottom="@+id/username_edittext" android:layout_alignparentleft="true" android:paddingleft="10dp" android:text="Όνομα χρήστη:" android:text="textview" /> </relativelayout>
Comments
Post a Comment