Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to align an item to the right of it's parent center? (android layouts)

i want something like this:
enter image description here

i palyed with android relativelayout and it's tag like : android:layout_centerHorizontal="true" , and this give me this:

enter image description here

i player with other tags and combine them, but no success.

so is there any way to do this?

like image 532
mehdok Avatar asked Dec 05 '22 09:12

mehdok


2 Answers

Try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="20dp"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:background="@android:color/black" >
</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/linearLayout1"
    android:text="YOUR TEXT" />

</RelativeLayout>
like image 58
Lia Pronina Avatar answered Jan 17 '23 06:01

Lia Pronina


try this

<RelativeLayout 
        android:layout_width="fill_parent"
        android:background="#FFFFFF"
        android:layout_height="wrap_content">


        <View 
            android:layout_width="10dp"
            android:layout_height="1dp"
            android:layout_centerInParent="true"
            android:id="@+id/dummy"
            />
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SDADASd"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/dummy"
            android:textColor="#000000"

            />
    </RelativeLayout>
like image 38
rachit Avatar answered Jan 17 '23 05:01

rachit