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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:59:28+00:00 2026-05-26T10:59:28+00:00

I am adding textview on runtime and I want textview to be added on

  • 0

I am adding textview on runtime and I want textview to be added on the last line or next line if it cannot fit on the last line. I am trying to use RelativeLayout . I am trying to specify params like ALIGN_PARENT_LEFT But this is not working. So, I wanted to ask which layout should I use ?

RelativeLayout ll = (RelativeLayout) findViewById(R.id.categorylayout);
    //  ll.setGravity(Gravity.LEFT );
        RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) ll.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);  
        for(int i =0 ; i<tags.size();i++){
            TextView tt = new TextView(this);
            tt.setText(tags.get(i));
            tt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            tt.setBackgroundColor(Color.RED);
            ll.addView(tt  );
        }
  • 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-26T10:59:28+00:00Added an answer on May 26, 2026 at 10:59 am

    you are not using params, I believe you intended to use

    tt.setLayoutParams(params);
    

    instead of

    tt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    

    However this way TextViews will overlap each other, so you might also want to .addRule() for vertical alignment inside your loop.

    edit

    for(int i =0 ; i<tags.size();i++){
        TextView tt = new TextView(this);
        tt.setText(tags.get(i));
        tt.setId(i+1);
    
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
        if (i == 0)
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        else 
            params.addRule(RelativeLayout.BELOW, i);
    
        tt.setLayoutParams(params));
        tt.setBackgroundColor(Color.RED);
        ll.addView(tt);
    }
    

    brief exlpanation: you set ids for each TextView (as explained here, RelativeLayout resolves only ids for each children), and so next one will be below previous. First one is aligned with parent’s top. I haven’t tested it, but at least it is starting point.

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

Sidebar

Related Questions

I want to use external fonts in my app. I have tried adding new
I am trying to display a text box using textView.I am adding some data
I have a TextView in my application. I want to align the text in
I have a textView with some text in it. I want to delete the
I'm adding in a TextView programatically to a linear layout. I can see the
I can display the contents of a file in a TextView by adding the
I'm currently working on extending a TextView, adding an outline around the text. Thus
I am facing a problem of adding overlays. I want to add button which
what i trying to do is i am adding some text in the edit
I'm trying to implement a custom ProgressBarPreference, adding at the bottom of a default

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.