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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:43:18+00:00 2026-06-17T08:43:18+00:00

I have a ViewSwitcher layout which used as a cell inside a TableLayout. The

  • 0

I have a ViewSwitcher layout which used as a cell inside a TableLayout.

The ViewSwitcher contains two views and I have implemented an OnClickListener on the first child in order to switch views on click.

The problem is that when one cell of a TableRow is clicked, the view is switched, but all the other cells on the same row are resized magically.

  • Example 1:

The view displays:

no action screen

When I click on the left cell it gives:

select left cell

And when I finally click on the right cell it gives:

select right cell

  • Example 2:

The view displays:

no action screen

When I click on the right cell it gives:

select right cell

And when I finally click on the left cell it gives:

select left cell

My screenshots are not very high quality but one can see that the cell that has not been clicked is truncated as if it was moved down under the parent view from a few pixels.

The proof is that the green border does not show on the bottom.

I have taken a screenshot of the hierarchy viewer for example 1 step 2 here:

enter image description here

  • The big rectangle on the background with the thin red border is the table row.
  • The rectangle with the white border on the left is the clicked cell (ViewSwitcher).
  • The red rectangle with the strong red border is the messed up cell (ViewSwitcher).

So you can see that it’s been moved a few pixels below its original position which makes a blanck space on top of it inside the table row, and the bottom part of the cell is not visible.

I really don’t know what’s going so if you have an idea or if you’d like to try, here is the code:

The activity:

package my.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.ViewSwitcher;

public class SampleActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        TableLayout table = (TableLayout) mInflater.inflate(R.layout.content, null);
        TableRow row = new TableRow(this);

        ViewSwitcher cell1 = (ViewSwitcher) mInflater.inflate(R.layout.cell, null);
        cell1.findViewById(R.id.cell_view).setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                ((ViewSwitcher) v.getParent()).showNext();
            }
        });
        row.addView(cell1);

        ViewSwitcher cell2 = (ViewSwitcher) mInflater.inflate(R.layout.cell, null);
        cell2.findViewById(R.id.cell_view).setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                ((ViewSwitcher) v.getParent()).showNext();
            }
        });
        row.addView(cell2);

        table.addView(row);
        setContentView(table);
    }
}

The layout content.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</TableLayout>

The layout cell.xml:

<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cell"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
android:background="@drawable/cellborder"
android:padding="1px"
    >
    <TextView
        android:id="@+id/cell_view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/select"
        android:text="TextView" />
    <EditText
        android:id="@+id/cell_edit"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:hint="EditText" />
</ViewSwitcher>

And the drawables if you also want the colors:

border.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape= "rectangle"
    >
    <solid android:color="#FFFFFFFF"/>
    <stroke android:width="1dp"  android:color="@android:color/holo_green_light"/>
</shape>

select.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:startColor="@android:color/white"
                android:endColor="@android:color/white"/>
        </shape>
    </item>

    <item android:state_focused="true" android:state_pressed="true">
        <shape>
            <gradient
                android:startColor="@android:color/holo_blue_light"
                android:endColor="@android:color/holo_blue_dark"/>
        </shape>
    </item>

    <item android:state_pressed="true">
        <shape>
            <gradient
                android:startColor="@android:color/holo_green_light"
                android:endColor="@android:color/holo_green_dark"/>
        </shape>
    </item>

    <item>
        <shape>
            <gradient
                android:startColor="@android:color/holo_orange_light"
                android:endColor="@android:color/holo_orange_dark"/>
        </shape>
    </item>
</selector>
  • 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-17T08:43:18+00:00Added an answer on June 17, 2026 at 8:43 am

    I surrounded each component in you cell.xml with a linear layout and it fixed your issue. Give it a try:

       <?xml version="1.0" encoding="utf-8"?>
       <ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/cell"
       android:layout_width="fill_parent"
       android:layout_height="50dp"
       android:background="@drawable/cellborder"
       android:padding="1px" >
    
       <LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" >
    
    
       <TextView
           android:id="@+id/cell_view"
           android:layout_width="fill_parent"
           android:layout_height="50dp"
           android:background="@drawable/select"
           android:text="TextView" />
    
       </LinearLayout>
    
       <LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" >
    
               <EditText
               android:id="@+id/cell_edit"
               android:layout_width="fill_parent"
               android:layout_height="50dp"
               android:hint="EditText" />
        </LinearLayout>
    
    </ViewSwitcher>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a viewSwitcher containing two views. Is it possible that when I am
Have have created a child of UITableViewCell , MenuItem which contains functionality for my
Have two tables say ABC and XYZ and contain one column which data will
I currently have implemented an ImageSwitcher in my app, which slides through an array
I have a file toto.xml with a layout that contains a TextView and a
Have a simple iPhone app with a single UIViewController and two Views in one
I couldn't able to deal with viewswitcher. I want to have two buttons at
I have an Activity which is used as an image gallery and works quite
I have created one advertisement control which consists of ViewSwitcher.... in that control i
I have an xml layout with 3 pages of ImageViews inside a custom view

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.