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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:23:26+00:00 2026-06-03T08:23:26+00:00

I wrote the layout below for an Activity , just a title and four

  • 0

I wrote the layout below for an Activity, just a title and four buttons in a 2×2 format:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/layout_main"
    android:gravity="center"
    android:background="@drawable/bgr_main">

<TableRow android:gravity="center_horizontal" >
    <ImageView
        android:id="@+id/img_qtitle"
        android:contentDescription="@string/qtitle_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/app_title" />
</TableRow>

<TableRow android:gravity="center_horizontal" >
    <Button
        android:id="@+id/button_showlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/button_list"
        android:onClick="showList" />

    <Button
        android:id="@+id/button_playrandom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/button_play"
        android:onClick="playRandom" />     
</TableRow>

<TableRow android:gravity="center_horizontal" >
    <Button
        android:id="@+id/button_playfav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/button_fav"
        android:onClick="playLastFav" />

    <Button
        android:id="@+id/button_showmore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/button_more"
        android:onClick="showMore" />       
</TableRow> 
</TableLayout >

The title image is not as wide as the row’s couple of button (plus padding). My problem is that the first button images in each row are shown horizontally stretched. What’s the way to normalize non-symmetric tables?


v.2 after gopher

<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/layout_main"
    android:gravity="center"
    android:background="@drawable/bgr_main">

<TableRow android:gravity="center_horizontal" >
    <ImageView
        android:id="@+id/img_qtitle"
        android:contentDescription="@string/qtitle_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/quieto_title" />
</TableRow>

<TableRow android:gravity="center_horizontal" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <Button
        android:id="@+id/button_showlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_margin="5dip"
        android:background="@drawable/button_list"
        android:onClick="showList" />   

    <Button
        android:id="@+id/button_playrandom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_margin="5dip"
        android:background="@drawable/button_play"
        android:onClick="playRandom" />
    </LinearLayout> 
</TableRow>

<TableRow android:gravity="center_horizontal" >    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <Button
        android:id="@+id/button_playfav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_gravity="left"
        android:background="@drawable/button_fav"
        android:onClick="playLastFav" />

    <Button
        android:id="@+id/button_showmore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_margin="5dip"
        android:background="@drawable/button_more"
        android:onClick="showMore" />
    </LinearLayout> 
</TableRow> 
</TableLayout >

That WORKS! Eclipse says: “This LinearLayout layout or its TableRow parent is useless”, but for me it’s ok. I won’t tell the client!

  • 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-03T08:23:27+00:00Added an answer on June 3, 2026 at 8:23 am

    A screenshot of what you’re seeing will help.

    ImageView not filling entire table

    In the tablelayout properties, try specifying android:stretchColumns="*" which will allow the columns to stretch to fill the table. I believe if all the columns are allowed to stretch (as the * denotes), then they will stretch so they are even (take up the same amount of space).

    Button being stretched

    You specified layout_width="wrap_content" which normally would achieve what you want, but in the case of Table Layout, you can’t specify a width. This is from the TableRow android documentation:

    The children of a TableRow do not need to specify the layout_width and layout_height attributes in the XML file. TableRow always enforces those values to be respectively MATCH_PARENT and WRAP_CONTENT.
    

    So you need to put another container in the Table Row, put your button in that container and set your button to wrap & align to the middle. Something like this should work:

    <TableRow ...>
        <!-- Create a container -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- Place button inside Container -->
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                <!-- Place button in the middle of the container -->
                android:layout_gravity="center"
                .../>
       </LinearLayout>
    </TableRow>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have just started android programming, wrote a quick code, and havn't managed to
I wanna use custom font file. For that below is my code XML file:
My question has three parts. My Layout consists of 26 Buttons: ButtonA, ButtonB, ButtonC...ButtonZ
I am trying to write my thesis in latex... Cannot get the layout straight
I'm having a Firefox-specific issue with a script I wrote to create 3d layouts.
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate
I wrote a custom URL rewriting module, to take certain paths and map them
I wrote a small internal web app using (a subset of) pylons . As
I wrote a program that forks some processes with fork(). I want to kill
I wrote a routine to remove pounds and ids from sharepoint fields that worked

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.