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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:41:17+00:00 2026-06-17T05:41:17+00:00

I want to build generic 5X5 views that baced on table layout (all the

  • 0

I want to build generic 5X5 views that baced on table layout (all the view have equal width and height)
as you can see my code isn’t generic. what to do? i tried to play with fill parent and match parent … please help.
and i want the tableLaayout width and height will be equal.

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical"
tools:context=".MainActivity" >

<TableLayout
    android:id="@+id/tableBoard"
    android:layout_width="wrap_content"
    android:layout_height="313dp"
    android:layout_centerHorizontal="true" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.example.com.worfield.barak.Square
            android:id="@+id/view1"
            android:layout_width="60dp"
            android:layout_height=""
            android:layout_margin="1dp"

            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view2"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"                         
            android:background="@drawable/square" />
        <com.example.com.worfield.barak.Square
            android:id="@+id/view3"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"

            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
           android:id="@+id/view4"
           android:layout_width="60dp"
           android:layout_height="60dp"
           android:layout_margin="1dp"

           android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view5"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"

            android:background="@drawable/square" />

    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.example.com.worfield.barak.Square
            android:id="@+id/view6"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:layout_weight="0.24"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view7"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view8"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view9"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view10"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />
    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.example.com.worfield.barak.Square
            android:id="@+id/view11"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view12"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view13"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view14"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view15"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />
    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.example.com.worfield.barak.Square
            android:id="@+id/view16"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view17"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view18"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view19"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view20"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />
    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:id="@+id/tableRow5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.example.com.worfield.barak.Square
            android:id="@+id/view21"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view22"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

        <com.example.com.worfield.barak.Square
            android:id="@+id/view23"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view24"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"

            android:background="@drawable/square" />

       <com.example.com.worfield.barak.Square
            android:id="@+id/view25"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="1dp"
            android:background="@drawable/square" />
    </TableRow>
</TableLayout>

<Button
    android:id="@+id/bStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tableBoard"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="16dp"
    android:text="Do Something" />

<TextView
    android:id="@+id/tvError"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/bStart"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="18dp"
    android:text="TextView" />

  • 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-17T05:41:18+00:00Added an answer on June 17, 2026 at 5:41 am

    Create a special view which can only be square. You should override onMeasure method accordingly. For exmaple you can do the following:

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
        //final int height = getMeasuredHeight();
        final int width = getMeasuredWidth();
    
        setMeasuredDimension(width, width);
    }
    

    TableRow is LinearLayout. So you can use layout_weight to spread 5 childs equally horizontally. Set layout_width = “0” and layout_weight = “1” for all childs of a row. When measured each child’s width will be 1/5 of tableRow width and child’s height will be equal it’s width.

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/llMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background"
        android:orientation="vertical" >
    
        <TableLayout
            android:id="@+id/tableBoard"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >
    
            <TableRow
                android:id="@+id/tableRow5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
    
                <com.kamagames.pokerist.Squire
                    android:id="@+id/view25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:background="#00ff00" />
    
                <com.kamagames.pokerist.Squire
                    android:id="@+id/view25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:background="#ff0000" />
    
                <com.kamagames.pokerist.Squire
                    android:id="@+id/view25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:background="#0000ff" />
    
                <com.kamagames.pokerist.Squire
                    android:id="@+id/view25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:background="#ffff00" />
    
                <com.kamagames.pokerist.Squire
                    android:id="@+id/view25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:background="#00ffff" />
            </TableRow>
        </TableLayout>
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a python program that deletes all the photos from my
I want to externalize generic parts of my large build file in order to
I want build a sketch pad app on iPhone, I assume that this type
I want to build flash application that can detect the user eyes color and
I want to build a form_tag that will allow me to post a new
I want to build my own listView with selectedItem and Itemsource. I have started
I have an many class with BeginDate and EndDate properties, I want to build
I would like to build a generic class that I can use to implement
i want to build a generic search window using linq to sql. This is
I have a generic dispatcher that takes in parameters and then make $.ajax() As

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.