Ashok Sinh Ashok Sinh - 1 month ago 8
Android Question

Android TextView Right Side

I am trying to set imageview in left side and text view right side in LinearLayout. I am not able to set TextView as end of LinearLayout. How can I do it ?enter image description here

I want Your Name on end of LinearLayout in line of imageview.

My XML is like below.



<LinearLayout
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

<ImageView
android:id="@+id/action_qod_save"
android:src="@android:drawable/ic_menu_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txtusername"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:textSize="18sp"
android:text="Your Name"
android:gravity="center"
android:layout_gravity="left"
android:textStyle="italic"
android:typeface="sans"
android:textColor="@android:color/black"/>

</LinearLayout>





Full XML



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffeeeeee"
>


<android.support.v7.widget.CardView
android:layout_centerInParent="true"
android:layout_margin="24dp"
app:cardCornerRadius="24dp"
android:elevation="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>


<LinearLayout

android:paddingTop="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/imgview"
android:layout_width="128dp"
android:layout_height="128dp"
android:src="@drawable/ic_launcher"
app:civ_border_color="#EEEEEE"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="@color/colorPrimary"/>
</LinearLayout>

<TextView
android:background="@color/white"
android:id="@+id/txtquote"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="8dp"
android:textSize="19dp"
android:gravity="center"
android:textStyle="italic"
android:typeface="sans"
android:lines="5"
android:textColor="@color/colorPrimaryDark"
android:text="Quote of The Day Text Will be Here">
</TextView>

</LinearLayout>


<LinearLayout
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

<ImageView
android:id="@+id/action_qod_save"
android:src="@drawable/new_share_btn"
android:layout_width="36dp"
android:layout_height="36dp" />

<TextView
android:id="@+id/txtusername"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:textSize="18sp"
android:text="Your Name"
android:gravity="center"
android:layout_gravity="left"
android:textStyle="italic"
android:typeface="sans"
android:textColor="@color/colorPrimaryDark"/>

</LinearLayout>


<TextView

android:background="@color/colorPrimary"
android:id="@+id/lblTitle"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:gravity="center"
android:textStyle="bold"
android:textSize="24sp"
android:shadowColor="@android:color/white"
android:shadowDx="-5"
android:shadowDy="-5"
android:shadowRadius="2"
android:textColor="#ffffff"
android:text="Status Of The Day">

</TextView>

</LinearLayout>


</android.support.v7.widget.CardView>

</RelativeLayout>





Thanks

Answer

use this

<RelativeLayout

            android:layout_marginBottom="12dp"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           >

                <ImageView
                    android:id="@+id/action_qod_save"
                    android:src="@android:drawable/ic_menu_save"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/txtusername"
                android:layout_height="match_parent"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:text="Your Name"
                android:textStyle="italic"
                android:typeface="sans"
                android:textColor="@android:color/black"
                 android:layout_alignParentRight="true"/>

        </RelativeLayout>

if you want only linear layout then Do this

<LinearLayout
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="12dp"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

                <ImageView
                    android:id="@+id/action_qod_save"
                    android:src="@android:drawable/ic_menu_save"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

      <View
      android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
       android:layout_weight="1"
            />
            <TextView
                android:id="@+id/txtusername"
                android:layout_height="match_parent"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:text="Your Name"
                android:gravity="center"
                android:layout_gravity="left"
                android:textStyle="italic"
                android:typeface="sans"
                android:textColor="@android:color/black"/>

        </LinearLayout>

but it is not suggested as it will place an empty view in between