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 6079745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:58:55+00:00 2026-05-23T10:58:55+00:00

I have lists of LinearLayouts with horizontal orientation each one containing two textviews added

  • 0

I have lists of LinearLayouts with horizontal orientation each one containing two textviews added dynamically.
This LinearLayout is finally wrapped into master LinearLayout.

I want the second textview of each linear layout to be right aligned progrmatically. How can I do this dynamically.

Here’s sample code:

LinearLayout placeHolderLinearLayout =  (LinearLayout)findViewById(R.id.listhosts);

//Several such layouts with 2 text views will be added to placeholder
LinearLayout l = new LinearLayout(this);
l.setClickable(true);

TextView h = new TextView(this);
h.setText("left");
h.setSingleLine(true);


TextView t = new TextView(this);
t.setText("right");
t.setSingleLine(true);

l.addview(h);
l.addview(t);

placeHolderLinearLayout.addView(l);

There is android:layout_alignParentRight attribute. But how to set this dynamically in this case. Any clue?

  • 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-05-23T10:58:55+00:00Added an answer on May 23, 2026 at 10:58 am

    The android:layout_alignParentRight can only be applied to a view if its parent is a RelativeLayout. Change your container to that, and the 2 sub-views can use any of the layout_alignParent* attributes.

    If you can’t do this programatically (which I can’t see how to do quickly), then you could always define your inner layout in xml (where you can easily get the layout correct) and inflate manually via:

    LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View l = vi.inflate(R.layout.inner_relative_layout, null);
    
    TextView leftTextView = (TextView) l.findViewById(R.id.left_text);
    leftTextView.setText("left");
    // ... fill in right text too
    
    placeHolderLinearLayout.addView(l);
    

    Edit: added layout definition

    Use a layout like this, and inflate it in the code as above:

    <RelativeLayout android:id="@+id/inner_relative_layout" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <TextView android:id="@+id/left_text" android_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
        <TextView android:id="@+id/right_text" android_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </RelativeLayout>
    

    You will be creating multiple of these layouts for each item you’re adding to your list.

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

Sidebar

Related Questions

I have lists of variable length where each item can be one of four
I have two lists of objects. Each list is already sorted by a property
I have two lists, each on different tabs (sub-sites) of the site. I would
I have a Custom ListView that contains a vertical LinearLayout of horizontal LinearLayouts for
this is the layout i have: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=horizontal android:minHeight=?android:attr/listPreferredItemHeight> <LinearLayout android:orientation=vertical
I have custom list_row : <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=match_parent android:orientation=horizontal android:layout_width=match_parent android:layout_height=wrap_content android:baselineAligned=false> <Button
I have two lists of custom objects and want to update a field for
I have two lists and I want to select items that are not in
I have 2 lists each of equal size and am interested to combine these
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that

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.