I have a nine-patched image, which I set the background for my textview during activity.onCreate(). Textview has WRAP_CONTENT layout for both height+width. It's created from code, not from XML.
_btnCurrent.setBackgroundResource(R.drawable.button_menu_off);
This works fine. I have an other nine-patched image, same size, only difference is it's color. Now if I call setBackgroundResource later with the other image, it will increase the height of the textview, almost to double. This other call happens from the textview.onClick()
_btnCurrent.setBackgroundResource(R.drawable.button_menu_on);
If I call it again (clicking again in the textview), no effect. Which is good, and I suppose it to happen for the first click as well. So:
Activity.onCreate()
{
btnCurrent= new TextView(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
btnCurrent.setBackgroundResource(R.drawable.button_menu_hs_off);
btnCurrent.setPadding(15, 5, 15, 5);
btnCurrent.setGravity(Gravity.CENTER);
btnCurrent.setText( GetString(id) );
btnCurrent.setOnClickListener(this);
}
onClick()
{
_btnCurrent.setBackgroundResource(R.drawable.button_menu_on);
}
onCreate(); // -> called by Android during startup -> OK
....
onClick(); // called when user clicks on it -> btnCurrent has double height
....
onClick(); // called when user clicks again -> btnCurrent has same double height, no change in size
....
onClick(); // called when user clicks again -> btnCurrent has same double height, no change in size
I tried to set the _btnHSCurrent.setBackgroundResource(0); before setting the new image, but does not help.
Why does this happen?
@Edit
I did: _btnCurrent.setBackgroundResource(R.drawable.button_menu_off); during the Activity.onCreate().
Then in the textview.onClick(), I call:
_btnCurrent.setBackgroundResource(R.drawable.button_menu_on);
and this will double the height. Clicking again, again, again, does not change the size anymore, only at first click.