1. Are you ready for the Galaxy S20? Here is everything we know so far!

How relayout view

Discussion in 'Android Development' started by andypaul1, Dec 29, 2012.

  1. andypaul1

    andypaul1 Lurker
    Thread Starter

    Hi,
    I am tryout a very simple thing in an activity. It has three components laid out vertically in a linear layout - button, textview1, and textview2. All I want to do is to toggle visibility of textview1 when the button is clicked. So I have the following onclick handler for the button:

    [HIGH]public void onClickMe(View view){
    TextView thetext =(TextView)findViewById(R.id.thetext);

    if(displayText){
    thetext.setVisibility(TextView.INVISIBLE);
    } else {
    thetext.setVisibility(TextView.VISIBLE);
    }
    findViewById(R.id.optionView).invalidate();
    thetext.invalidate();
    findViewById(R.id.optionView).getParent().requestLayout();
    //thetext.requestLayout();

    displayText = !displayText;
    }[/HIGH]
    The textview does get visible and invisible but the problem is when the textview is made invisible it leaves a big gap between the button and the textview2. I would like the textview2 to be moved the the position where textview1 was. I think it is something to do with relayout but not sure what needs to be done here. I tried multiple things as shown in the code above. But it is not happening. What am I doing wrong?

    thank you!
     



    1. Download the Forums for Android™ app!


      Download

       
  2. andypaul1

    andypaul1 Lurker
    Thread Starter

    I found the answer. I need to use TextView.GONE instead of TextView.INVISIBLE. bummer!
     
Loading...

Share This Page

Loading...