Okan
Okan

Reputation: 1389

Aligning in linearlayout

I am using linear layout.I have to achive this :

enter image description here

I tried something like this:

<View
    android:layout_width="88dp"
    android:layout_height="0.25dp"
    android:layout_marginLeft="43dp"
    android:layout_marginTop="26dp"
    android:layout_gravity="left"
    android:background="#ffffff" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="login to app"
    android:textColor="@color/white"
    android:textSize="10sp" />
<View
    android:layout_width="88dp"
    android:layout_height="0.25dp"
    android:layout_gravity="right"
    android:layout_marginRight="43dp"
    android:background="#ffffff" />

But result is:

enter image description here

How can I resolve it ?

Upvotes: 1

Views: 54

Answers (1)

frogatto
frogatto

Reputation: 29287

Add center_vertical to all your android:layout_gravity. For example:

android:layout_gravity="left|center_vertical"

UPDATE #1

<LinearLayout orientation="vertical">
    <FrameLayout
        layout_width="match_parent"
        layout_height="wrap_content">

        <View
            android:layout_width="88dp"
            android:layout_height="0.25dp"
            android:layout_marginLeft="43dp"
            android:layout_marginTop="26dp"
            android:layout_gravity="left|center_vertical"
            android:background="#ffffff" />

       <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center"
           android:text="login to app"
           android:textColor="@color/white"
           android:textSize="10sp" />

       <View
           android:layout_width="88dp"
           android:layout_height="0.25dp"
           android:layout_gravity="right|center_vertical"
           android:layout_marginRight="43dp"
           android:background="#ffffff" />        

    </FrameLayout>

    <!-- Other stuff -->

</LinearLayout>

Upvotes: 1

Related Questions