Android: How To Create This Simple Layout?
I need to create a simple layout with two form widgets (for example - two buttons). The first one must fill all available width of the parent layout and the second one must have so
Solution 1:
The easiest way to do this is using layout_weight
with LinearLayout
. Notice the width of the first TextView is "0dp"
, which means "ignore me and use the weight". The weight can be any number; since it's the only weighted view, it will expand to fill available space.
<LinearLayoutandroid:orientation="horizontal"android:layout_width="match_parent"android:layout_height="wrap_content"
><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"
/><TextViewandroid:layout_width="25dp"android:layout_height="wrap_content"
/></LinearLayout>
Solution 2:
You can accomplish that with a RelativeLayout or a FrameLayout.
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:layout_marginLeft="5dp"android:background="#ccccee"android:text="A label. I need to fill all available width." /><TextViewandroid:layout_width="20dp"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:paddingRight="5dp"android:background="#aaddee"android:text=">>" /></RelativeLayout>
Post a Comment for "Android: How To Create This Simple Layout?"