Android: align labels and buttons in multiple lines -
i go nuts on layout. here's i'm trying achieve. simple layout having label (textview) or edit field (edittext) on left side , button on right side. want labels , buttons vertically adjusted - meaning buttons of same width , labels too.
but how this? tried linearlayout vertical orientation , each line linearlayout horizontal orientation , inside label has layout_weight of 8 , button 1. still not guarantee want!
this current result. can see buttons not nicely aligned.
this layout:
here's xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <edittext android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:hint="test_test_blabla" android:layout_weight="8" android:textsize="24sp" android:fontfamily="sans-serif-thin" android:layout_gravity="left" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/action_scan" android:textsize="24sp" android:fontfamily="sans-serif-thin" android:layout_weight="1" android:layout_gravity="right" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:text="17:35" android:layout_weight="8" android:textsize="24sp" android:fontfamily="sans-serif-thin" android:layout_gravity="left" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/action_pick_time" android:textsize="24sp" android:fontfamily="sans-serif-thin" android:layout_weight="1" android:layout_gravity="right" /> </linearlayout> </linearlayout>
using relativelayout
can achieve desired layout as:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <edittext android:id="@+id/edittext" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignright="@+id/textview" android:layout_toleftof="@+id/button" android:fontfamily="sans-serif-thin" android:hint="test_test_blabla" android:textsize="24sp"/> <button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_torightof="@+id/textview" android:fontfamily="sans-serif-thin" android:hint="scan" android:textsize="24sp"/> <textview android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/button2" android:layout_alignparentleft="true" android:layout_below="@+id/edittext" android:layout_toleftof="@+id/button2" android:fontfamily="sans-serif-thin" android:text="17:35" android:textsize="24sp"/> <button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_below="@+id/button" android:fontfamily="sans-serif-thin" android:hint="pick time" android:textsize="24sp"/> </relativelayout>
the key layout attribute used match size android:layout_alignright="@+id/textview"
on first edittext
referencing textview
below.
Comments
Post a Comment