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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:05:17+00:00 2026-05-30T12:05:17+00:00

What I thought would be a fairly straightforward layout is not turning out to

  • 0

What I thought would be a fairly straightforward layout is not turning out to be.

I have several rows in a linear layout.

Each row has a “title”, a “tag” and a “description”.

The description appears below the title and tag and is no problem.

The title is of indeterminate length and should be aligned to top left. The tag should appear appear aligned to the right of the title (not necessarily the right edge of the parent, if the title is short). If there’s not enough room for both on a single line, the title should wrap and leave space for the tag.

The tag has it’s own style and behavior, and must be a separate element from the title.

In my limited experience, I’ve had the most luck with RelativeLayouts, so that was my first try:

import android.content.Context;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ExampleRow extends RelativeLayout {

    private TextView title;
    private TextView description;
    private TextView tag;

    public ExampleRow(Context context) {

        super(context);

        LayoutParams lp;        

        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        title = new TextView(context);
        title.setId(1);
        addView(title, lp);                 

        lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.BELOW, title.getId());
        description = new TextView(context);
        description.setId(2);
        addView(description, lp);       

        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.RIGHT_OF, title.getId());
        lp.addRule(RelativeLayout.ABOVE, description.getId());
        lp.setMargins(20, 0, 0, 0);
        tag = new TextView(context);
        addView(tag, lp);

    }
}

Long titles would force the tag off-screen.

I then tried nested LinearLayouts – the main container as a LinearLayout with vertical orientation, that had a “top row” that was a horizontal LinearLayout containing the title and the tag, and the bottom “row” being the description. That had the same issue described above.

Next I tried TableLayout, with 2 TableRows, but this not only failed but also showed strange quirks like not rendering certain rows at all, for reasons I don’t understand. The documentation on TableLayout and TableRow seems a little sparse, and I wasn’t able to find the Java equivalents of XML fields dealing with columns.

The layout needs to be in Java, not XML, for reasons too long and uninteresting to mention.

Any insight is appreciated.

TYIA.

/EDIT

to clarify the requirement, the best example I can think of would be in HTML.

<table>
  <tr>
    <td>title</td>
    <td>tag</td>
  </tr>
  <tr>
    <td colspan="2">description...</td>
  </tr>
</table>

the tag is always to the right of the title, but only as far right as it needs to be (depending on title width). the title would wrap once it forced the tag to the most extreme right.

  • 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-30T12:05:18+00:00Added an answer on May 30, 2026 at 12:05 pm

    I think this is the layout you’re after:

    public class TableLayoutCustom extends TableLayout {
    
        public TableLayoutCustom(Context context) {
            super(context);
    
            this.setColumnShrinkable(0, true);
            this.setColumnStretchable(1, true);
    
            TableRow row1 = new TableRow(context);
    
            TableRow.LayoutParams lp = new TableRow.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
            TextView title = new TextView(context);
            title.setText("Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum ");
    
            title.setId(1);
            row1.addView(title, lp);
    
            lp.setMargins(20, 0, 0, 0);
            TextView tag = new TextView(context);
            tag.setText("TAG ME");
            row1.addView(tag, lp);
    
            this.addView(row1);
    
            TableRow row2 = new TableRow(context);
            TableRow.LayoutParams tlp = new TableRow.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
            tlp.span = 2;
            TextView description = new TextView(context);
            description.setText("Description here");
            description.setId(2);
            row2.addView(description, tlp);
    
            this.addView(row2);
        }
    
    }
    

    If you change the text on the title to something shorter you will see that the tag “follows” the title.

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

Sidebar

Related Questions

Hey guys, I thought this would be fairly straightforward, but it's not it seems..maybe
I have a situation that I thought would be straightforward and fairly common but
I thought this would be fairly trivial but it's turned out be more difficult
I am currently using what I (mistakenly) thought would be a fairly straightforward implementation
I have a basic class that I extend fairly often. I thought it would
I'm trying to do something which I thought would be fairly simple. Get IIS
I thought this would be fairly easy, but I'm totally baffled. I want one
I'm trying to do something I thought would be fairly easy (as I suspect
I'm running what I thought would be a fairly straight forward calculation of financial
I have a fairly straightforward and common use case. A panel, in which resides

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.