Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:18:58+00:00 2026-06-09T15:18:58+00:00

I have a chat application and i need to align left or right rows

  • 0

I have a chat application and i need to align left or right rows in a listView.
My problem is that i can’t align each row left or right. They remain aligned left.
I inflate each layout based on the fallowing code

odd rows

   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/userprofile_view"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/odd" 
 android:layout_gravity="right">

 <TextView
  android:id="@+id/chat_message_odd"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:paddingLeft="10dp"  
  android:textColor="#66CD00"
   />
</FrameLayout>

even

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/userprofile_view"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/even" 
 android:layout_gravity="left">

 <TextView
  android:id="@+id/chat_message"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:paddingLeft="10dp"
  android:textColor="#000000"
   />
</FrameLayout>

Main layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF" >


    <ListView
    android:id="@+id/listMessages"
    android:layout_width="wrap_content"
    android:layout_height="0px"
    android:layout_weight="1"
    android:scrollbars="vertical"
    android:divider="@null"
    android:dividerHeight="0dp" />

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <EditText
        android:id="@+id/sendText"
        android:layout_width="253dp"
        android:layout_height="wrap_content"
        android:autoText="false"
        android:capitalize="none"
        android:ems="10"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textSize="16sp"
        android:hint="Enter text"
        >       
    </EditText>
    <Button
        android:id="@+id/send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="Send" />

</LinearLayout>

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:18:59+00:00Added an answer on June 9, 2026 at 3:18 pm

    make the TextView width match_parent and set it’s gravity to right.

    so make it:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/userprofile_view"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/odd" 
     >
    
     <TextView
      android:id="@+id/chat_message_odd"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="right"
      android:textColor="#66CD00"
       />
    </FrameLayout>
    

    or if you want a left aligned text which as a whole is on the right side of its parent, i would rather go for a RelativeLayout like this:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/userprofile_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/odd" >
    
    
    
        <TextView
            android:id="@+id/chat_message_odd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:paddingLeft="10dp"
            android:textColor="#66CD00" />
    
    </RelativeLayout>
    

    *** EDIT
    so simulating a list view I just did a vertical LinearLayout here:

        <RelativeLayout
            android:id="@+id/userprofile_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TextView
                android:id="@+id/chat_message_odd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:drawable/editbox_background"
                android:gravity="right"
                android:padding="10dp"
                android:text="foo bar"
                android:textColor="#66CD00" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/userprofile_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TextView
                android:id="@+id/chat_message_even"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="@android:drawable/editbox_background"
                android:gravity="right"
                android:padding="10dp"
                android:text="foo fighters"
                android:textColor="#f400" />
        </RelativeLayout>
    
    </LinearLayout>
    

    the above code creates a view like this:

    two lines of chat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Problem with chat application . my scenario: I need to build chat
I am developing an application in asp.net mvc where i need to have Chat
I have a chat application(Socket Programming) , for that consider I have 2 separate
I have a small application that I am building a Chat application into, so
I have 2 questions for you. Im creating an Application for Chat that relies
I want to build a simple web-interface application that can send/receive chat messages to/from
I have been working on a chat application and I need some suggestions to
I have an application that works similar to a chat, except beside the location
I making a simple chat application, and I need to write a claas that
I have a Rails application, that includes chat. Everything works fine, but now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.