1

I have 10 vertical TextViews that contain two numbers separated by a line like so.

seatStats2[i].setText(0 + "\n" + 0);

When first made visible these textViews appear fine: enter image description here

However if I click or longClick any of the ten buttons on screen the textViews stretch to include were the \n character would be on the first line (I tested out different number combinations to confirm this).

enter image description here

The methods for clicking the buttons are not linked to the TextViews in anyway (LongClicking is but both affect it). I'll provide the code for both listeners anyway. textView2 is the array holding the problematic textViews. I wish to maintain the textViews ability to stretch should I put greater numbers in but I want to remove the unnecessary stretching between clicks.

//Creates longClickListener, used for players to sit in or out.
    longClickListener = new View.OnLongClickListener() 
    {   
        @Override
        public boolean onLongClick(View v) 
        {
            if(moveButtonMode)
                return false;

            for(int i=0; i<10; i++)
            {
                //Each seat[i] will correspond with each imageButtoni+1
                if(v.getId() == (getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"))) 
                {
                    //If the seat is empty fill it, place a player in the seat and change the buttons colour to grey and setup stat panel
                    if(table.seats[i].getState().equals("empty"))
                    {
                        seatButton[i].setImageResource(R.drawable.black_seat);
                        table.seats[i].sit(new Player());
                        table.incrementOccupiedSeatCount();
                        seatStats[i].setVisibility(View.VISIBLE);
                        seatStats2[i].setVisibility(View.VISIBLE);
                        seatStats[i].setText(table.seats[i].getPlayer().getVpip() + "/" + table.seats[i].getPlayer().getPfr() + "/" + table.seats[i].getPlayer().getHands());
                        seatStats2[i].setText(table.seats[i].getPlayer().getSteal() + "\n" + table.seats[i].getPlayer().getThreeBet());
                    }
                    //If the seat is full, empty it
                    else
                    {
                        seatButton[i].setImageResource(R.drawable.dotted_box);
                        seatStats[i].setText("");
                        table.seats[i].sitOut();
                        table.decrementOccupiedSeatCount();
                        seatStats[i].setVisibility(View.INVISIBLE);
                        seatStats2[i].setVisibility(View.INVISIBLE);
                    }
                }
            }
            return true;
        }
    };



public void playerClickhandler(View v)
{
    if(!moveButtonMode)
    {
        for(int i = 0; i<10; i++)
        {
            if(v.getId() == getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"))
            {
                if(table.seats[i].getState() == "active")
                {
                    table.seats[i].setState("called");
                    seatButton[i].setImageResource(R.drawable.green_seat);
                }
                else if(table.seats[i].getState() == "called")
                {
                    table.seats[i].setState("raised");
                    seatButton[i].setImageResource(R.drawable.orange_seat);
                }
                else if(table.seats[i].getState() == "raised")
                {
                    table.seats[i].setState("active");
                    seatButton[i].setImageResource(R.drawable.grey_seat);
                }
            }
        }
    }
    else
    {
        for(int i = 0; i<10; i++)
        {
            if(v.getId() == getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"))
            {
                dealerBtnImage[table.getButtonSeat()].setVisibility(View.INVISIBLE);
                table.passButton(i);
                dealerBtnImage[table.getButtonSeat()].setVisibility(View.VISIBLE);
                moveButtonMode = false;
                nextHandButton.setEnabled(true);
            }
        }
    }
}

XML TextView Sample

<TextView android:id="@+id/textView19" android:visibility="invisible" android:background="#000000" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_toRightOf="@+id/imageButton9" android:layout_alignParentTop="true"></TextView>
enter code here
Declan McKenna
  • 4,321
  • 6
  • 54
  • 72
  • I'm sorry, but I can't see a difference between the two screenshots - would it be possible to highlight it? – Hannele Mar 20 '12 at 19:34
  • 1
    Look at the text views where the 0's are on top of each other. There's a little extra black space on the right side of them in the bottom picture – dymmeh Mar 20 '12 at 19:36
  • 1
    @Hannele The vertical TextViews have stretched to the right. It may seem petty but it is irritating when it happens every few clicks and makes my program very jittery. – Declan McKenna Mar 20 '12 at 19:37
  • 1
    If your textview's had transparent backgrounds, or if you used a control that supports transparent backgrounds, this wouldn't bother you. I don't see anything in the code sample you provided that would result in changing the width. (PS: You could try forcing the maximum width to only show X integers (assuming you can go higher than 9)) – Nahydrin Mar 20 '12 at 19:38
  • @Brian Graham Removing the black background is what I'll likely resort to if I can't figure this out. I'll give your max integer width idea a go now. – Declan McKenna Mar 20 '12 at 19:43
  • @dymmeh Thanks, I see it now. How curious! – Hannele Mar 20 '12 at 19:44
  • 1
    It might be some bug in Android. You could try to work around it by using 2 TextViews instead Could be a faster to fix it that way than finding your bug if it is even your bug :) – zapl Mar 20 '12 at 19:47
  • @BrianGraham How do I go about limiting the number of integers? I'm looking at TextViews documentation and can't find anything. – Declan McKenna Mar 20 '12 at 19:52
  • Ah maxEms. Didn't realize what ems were. Didn't work unfortunately. Wouldn't have been ideal anyway as limiting myself to 3ems would still have caused stretching if a three digit number wasn't present. – Declan McKenna Mar 20 '12 at 20:04
  • Do the buttons change size when clicked? I'm wondering if it's triggering some sort of automatic resizing since the textviews are positioned relative to the buttons... – trutheality Mar 20 '12 at 20:49
  • No the image changes but I doubt that's it as clicking any button will stretch all buttons. Changing the image back does not revert the size either. – Declan McKenna Mar 20 '12 at 20:52
  • @Brian Graham I tried using a transparent background. The number is physically moved when the view stretches so it doesn't cover it up. :( – Declan McKenna Mar 20 '12 at 20:55
  • @zapl I suspect it is an android bug I had something similar happen a few months back. Seperate views would be awkward as I would need to maintain the size of each view so it's consistent with the largest view. – Declan McKenna Mar 20 '12 at 20:55
  • 1
    @Deco there is probably a way to do that with clever layout. E.g. in your `` `android:gravity="right" android:ems="10"` would always be wide enough for 10 m's (since that's typically the widest character) and the text would be on the right of the textview. – zapl Mar 20 '12 at 21:04
  • For anyone with a similar problem I ended up creating two seperate textViews to get round this as zapl suggested. – Declan McKenna Mar 23 '12 at 17:48

1 Answers1

1

I cannot see anything wrong in the code you provided!

Therefore my best bet would be an additional whitespace in one of the following getters:

table.seats[i].getPlayer().getSteal()

or

table.seats[i].getPlayer().getThreeBet()  // this would be more likely

As from your code I suppose that they are representing a String, maybe you could invoke a trim() on them and see if it helped.

But as already said this is just a suggestion.

Hope this helpes, have Fun!

SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • Neither trimming or adding a space had any effect :( Oddly enough adding the space didn't even show up at all prior to the unwanted stretch. It may have doubled the stretch whilst the space was on the first line which which would confirm it's the first line getting the phantom character. Have no idea why this character is added when we make an unrelated longclick which doesn't so much as touch the TextView in question. I think it's a bug, it's similar to this problem. http://stackoverflow.com/questions/8022980/why-does-setalpha-act-on-all-my-buttons-whilst-setimageresource-acts-on-just – Declan McKenna Mar 21 '12 at 14:03
  • Sad to hear. I hope you'll get around this problem! Cheers! – SimonSez Mar 21 '12 at 14:33