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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With