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

The Archive Base Latest Questions

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

I am trying to duplicate the following layout programmatically; however, the setGravity and setPadding

  • 0

I am trying to duplicate the following layout programmatically; however, the setGravity and setPadding don’t seem to have an effect:

I’m trying to recreate the textviews within the TableRows (note that there’s padding and the second text view is right aligned). Also, I’m trying to recreate additional entries because they are dynamic:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/myinfo_root"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:scrollbars="vertical"
        >
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainTable"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Text1"
            android:padding="3dip" />

        <TextView
            android:id="@+id/text1"
            android:text="TBD"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Text2"
            android:padding="3dip" />

        <TextView
            android:id="@+id/text2"
            android:text="TBD"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    . . .

Here’s a code snippet to add the TextViews. It seems to work but the entries don’t have padding and are not right aligned.

    int n = 0;
    TableLayout table = (TableLayout) findViewById(R.id.mainTable);

    for (int j=0; j<2; j++) {
        Log.v(LOG_TAG, "entering for loop");
        n++;

        TableRow tr = new TableRow(getApplicationContext());
        tr.setId(100+n);

        String key = "hello";
        float value = (float) 1.388);
        value = value/3600;

        TextView tvDynamicKey = new TextView(getApplicationContext());                      
        TextView tvDynamicUnit = new TextView(getApplicationContext());

        tvDynamicUnit.setText(Float.toString(value));
        tvDynamicUnit.setGravity(Gravity.RIGHT);
        tvDynamicKey.setText(key + " " + n); 
        tvDynamicKey.setPadding(3, 3, 3, 3);
        tvDynamicUnit.setPadding(3, 3, 3, 3);
        tr.addView(tvDynamicKey);
        tr.addView(tvDynamicUnit);
        table.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-05-26T14:28:47+00:00Added an answer on May 26, 2026 at 2:28 pm

    In your layout you always specify column1 for the left element (android:layout_column=”1″). But you don’t do it programmatically for the dynamic creation. You can do it like this. I tested it, it works on my environment.

     tvDynamicKey.setLayoutParams(new TableRow.LayoutParams(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to duplicate a swf loaded using greensocks LoaderMax but i don't seem
The following code is trying to remove any duplicate characters in a string. I'm
I'm trying to duplicate the effect used in the Firefox search box where, if
I am trying to remove duplicate items from vector using the following comparator bool
Possible Duplicate: c++ template problem Hi Everyone: I'm stuck trying to do the following:
I'm trying to duplicate the following behavior (WM6). Go to Settings -> About ->
I have a BST which has duplicate entries. I am trying to find duplicate
I have the following collection: UsersMod.users_list = Backbone.Collection.extend({ add : function(model) { var duplicate
trying to duplicate some PHP code in C#. The PHP code uses the uniqid
We are trying to duplicate one of our informix database on a test server,

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.