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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:41:58+00:00 2026-06-04T21:41:58+00:00

Sorry if the question isn’t informative enough. I am coding an app for ICS.

  • 0

Sorry if the question isn’t informative enough.
I am coding an app for ICS. I decided to use a TableLayout to create a grid for users to click stuff in.
For each row, I put in several TextViews and an ImageView of a 1dp vertical border between each two of them, all done programmatically in a loop.
Now I made each TextView clickable. When it’s clicked, its background changes to a blue drawable. However, I observe that the drawable does not fill the whole “grid” horizontally.
I think that the ImageView is perhaps occupying more space than it should (1dp). I have come up with or found many ways to stretch the TextViews but neither has worked for me.
Any ideas? Thanks in advance!

Edit: Here is the loop I am using – I know it’s a bit complicated so I didn’t post it 😛 The variables are already declared properly, of course.

for(int i=0; i<5; i++){
        tr = new TableRow(ctxt);
        tr.setGravity(Gravity.CENTER);
        for(int j=0; j<6; j++){ //add the text from an array
            tv = new TextView(ctxt);
            tv.setText(a[6*i+j]:null);
            tv.setTextSize(16);
            tv.setPadding(0, 4, 0, 4);
            tv.setGravity(Gravity.CENTER);
            tv.setClickable(true);
            tv.setBackgroundResource(R.drawable.list_selector_background);
            tv.setTag(39+6*i+j);
            tv.setOnClickListener(this);
            tr.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 2.0f));
            if(j<5){ //set the border
                border = new ImageView(ctxt);
                border.setImageResource(R.drawable.vert_border);
                tr.addView(border, new LayoutParams(0, LayoutParams.MATCH_PARENT, 0.0f));
            }
        }
        tl2.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 48));
        if(i<4){ //horizontal border
            tr = new TableRow(ctxt);
            tr.setMinimumHeight(1);
            tr.setBackgroundColor(color.bg_gray);
            tl2.addView(tr);
        }
    }
  • 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-04T21:42:00+00:00Added an answer on June 4, 2026 at 9:42 pm

    Well…this solution was inspired by Alfi, but mostly discovered by myself.
    I used a LayoutInflater to create the TableRow instead of constructing it.

    tr = (TableRow) li.inflate(R.layout.tbrow, null, false);
    

    where tbrow.xml is

    <?xml version="1.0" encoding="utf-8"?>
    <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="293" >
    </TableRow>
    

    since weight sum cannot be set in the program.
    the 293 here equals the total width of my TextViews and my ImageView borders. (48*6+1*5)
    Then in the program I can set exactly the width I want.
    As Alfi instructed, I set the width to zero then set the weight as the width I want.

    tr.addView(tv, new LayoutParams(0, LayoutParams.MATCH_PARENT, 48));
    

    as for the border:

    tr.addView(border, new LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    

    Hope this helps somebody else who stumbles upon this page.

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

Sidebar

Related Questions

Sorry if the title isn't really related to my question well enough, I wasn't
Sorry if the question isn't correct, I'm very new in Objective-C. I understand why
First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried
Sorry if this question isn't clear. The short story is that we had someone
Sorry if the question isn't phrased very well but I'm new to SSAS and
Sorry if the question isn't that clear in the title but I had a
Sorry if this question isn't allowed, but of these 3 which one do you
Sorry, still reasonably new to Javascript here, so hope this question isn't too embarrassingly
[I'm sorry that this isn't directly a programming question. But I have recently switched
I'm sorry if my question isn't clear. I have a class contain some properties

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.