Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand Android View as a full screen

Tags:

android

I have a linear layout which has five TextViews. Suppose a user clicks on the third TextView; I want to expand that TextView to the entire screen. In other words, I want to show the third TextView as full screen in the same activity above the other text views. How do I do this?

like image 996
Dalvinder Singh Avatar asked Oct 06 '10 10:10

Dalvinder Singh


Video Answer


1 Answers

If you initially set the height of each text view to wrap_content as below:

<TextView  
   android:id="@+id/textview1"
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:text="text1"
/>

Then attach a click handler that toggles the layout_height between wrap_content and fill_parent as below, you should achieve what you want.

final TextView tv1 = (TextView)findViewById(R.id.textview1);

    tv1.setOnClickListener(new OnClickListener(){           
        public void onClick(View arg0) {                
            if(tv1.getLayoutParams().height == LayoutParams.FILL_PARENT )
                tv1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
            else
                tv1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));                  
        }           
    });

You could also play around with layout_weight if you want to space out your text views initially.

like image 140
Gary Wright Avatar answered Oct 27 '22 00:10

Gary Wright