Reputation: 317
i dont know much about styling a layout, i want that some object will be attached to the right side of the creen, and some will be attached to the left side of the screen.
I have this xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
<TextView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="TextView"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
i want that the TextView
score
will be at the left side of the screen; i mean that left will be 0.
Upvotes: 0
Views: 47
Reputation: 2444
In a horizontal LinearLayout
, views are displayed from left to right. So, if you want score
to be fixed at the left, you have to put it, inside the LinearLayout
, but before both name
and date
.
If you want another view to be fixed to the right, you have to make the "middle" view to fill the remaining space. You usually would do this by setting its layout_width
to 0dp and it's layout_weight
to 1.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
... />
<TextView android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
... />
<TextView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
... />
</LinearLayout>
If you need more flexibility, try using a RelativeLayout
instead.
Upvotes: 1
Reputation: 24848
// try this way let me know still have some problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="TextView"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
<TextView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Upvotes: 1