matant matant - 3 months ago 5
Android Question

how to align textviews regarding to the layout background

i would like to know if there is a way to place all the textviews that start with little bit space regarding the layout they located. for example i want that in the follwoing image all the textvies will not touch in the border of layout sucah as the word "place","location","Between","When" are doing.

this is current situation:

enter image description here

and this is my xml code:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relativlayoutGcmMessage"
android:background="#ffffff">

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="@+id/separatorUp"
android:visibility="visible"
android:background="#FF0000"
android:layout_marginTop="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />


<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/textlayout"
android:layout_marginTop="5dp"
android:layout_below="@+id/separatorUp"
android:background="@drawable/edit_text_style_focused"
android:layout_margin="10dp"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User ,"
android:gravity="center"
android:id="@+id/textViewUser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textSize="20sp"
android:textColor="#FF0000" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="this is the message"
android:textSize="20sp"
android:layout_marginLeft="5dp"
android:layout_below="@+id/textViewUser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000" />

</RelativeLayout>




<LinearLayout
android:id="@+id/linearLayoutBtn"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<Button
android:text="Join"
android:id="@+id/ButtonJoin"
android:textColor="#ffffff"
android:background="#606060"
android:layout_margin="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
>
</Button>

<Button
android:text="Deny"
android:id="@+id/ButtonDeny"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:background="#606060"
>

</Button>

</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/relativeLayoutTextVals"
android:layout_marginTop="20dp"
android:layout_margin="10dp"
android:background="@drawable/edit_text_style_focused"
android:layout_below="@+id/textlayout"
android:layout_height="wrap_content">

<TableRow
android:layout_width="match_parent"
android:id="@+id/row2"
android:layout_below="@+id/row1"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Between:"
android:id="@+id/textViewbtwn"
android:textColor="#FF0000"
android:textStyle="bold"
android:textSize="20sp"
android:layout_weight="0.62" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Time"
android:id="@+id/textViewtime"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:layout_weight="1.45"
android:textColor="#000000" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:id="@+id/row3"
android:layout_below="@+id/row2"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Location:"
android:id="@+id/textViewloc"
android:textStyle="bold"
android:textColor="#FF0000"
android:textSize="20sp"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="place"
android:layout_marginLeft="10dp"
android:id="@+id/textViewPlace"
android:textSize="20sp"
android:layout_weight="2.28"
android:textColor="#000000" />




</TableRow>

<TableRow
android:layout_width="match_parent"
android:id="@+id/row1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="When:"
android:id="@+id/textViewWhen"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#FF0000"
android:layout_weight="51.15" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Date"
android:layout_marginLeft="10dp"
android:id="@+id/textViewDate"
android:textSize="20sp"
android:layout_weight="115.29"
android:textColor="#000000" />

</TableRow>


</RelativeLayout>


</RelativeLayout>

Answer

Try another approach as follows , it works as per your requirement

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativlayoutGcmMessage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <View
        android:id="@+id/separatorUp"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="25dp"
        android:background="#FF0000"
        android:visibility="visible" />


    <RelativeLayout
        android:id="@+id/textlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/separatorUp"
        android:layout_margin="10dp"
        android:layout_marginTop="5dp"
        android:padding="10dp">

        <TextView
            android:id="@+id/textViewUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:gravity="center"
            android:text="User ,"
            android:textColor="#FF0000"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/textViewUser"
            android:layout_marginLeft="5dp"
            android:text="this is the message"
            android:textColor="#000000"
            android:textSize="20sp" />

    </RelativeLayout>


    <LinearLayout
        android:id="@+id/linearLayoutBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/ButtonJoin"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="#606060"
            android:text="Join"
            android:textColor="#ffffff"></Button>

        <Button
            android:id="@+id/ButtonDeny"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="#606060"
            android:text="Deny"
            android:textColor="#ffffff">

        </Button>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/relativeLayoutTextVals"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textlayout"
        android:layout_margin="10dp"
        android:layout_marginTop="20dp">

        <LinearLayout
            android:id="@+id/row2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/row1"
            android:layout_margin="5dp">

            <TextView
                android:id="@+id/textViewbtwn"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Between:"
                android:textColor="#FF0000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textViewtime"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1"
                android:text="Time"
                android:textColor="#000000"
                android:textSize="20sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/row3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/row2"
            android:layout_margin="5dp">

            <TextView
                android:id="@+id/textViewloc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Location:"
                android:textColor="#FF0000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textViewPlace"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1"
                android:text="place"
                android:textColor="#000000"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/row1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_gravity="center"
            android:layout_margin="5dp"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                android:id="@+id/textViewWhen"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="When:"
                android:textColor="#FF0000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textViewDate"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1"
                android:text="Date"
                android:textColor="#000000"
                android:textSize="20sp" />

        </LinearLayout>


    </RelativeLayout>


</RelativeLayout>