Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yeah, I see the issue you mean. See example below, I have tested it to make sure it works. It's probably not the most elegant solution, but here goes.</p> <p>This time I have set the height to 0 and the weight to 1 for each text view. This makes each View take an equal slice of the height.</p> <pre><code>&lt;TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="0px" android:layout_weight="1" android:text="text1" /&gt; </code></pre> <p>In the activity code, I have the following instance declarations:</p> <pre><code>private TextView tv1; private TextView tv2; private TextView tv3; private TextView tv4; private TextView tv5; private boolean singleViewExpanded = false; private OnClickListener myOnClickListener = new OnClickListener(){ public void onClick(View arg0) { if(singleViewExpanded) { showAllViews(); singleViewExpanded = false; } else { // Hide all views apart from the clicked one hideAllViews(); arg0.setVisibility(View.VISIBLE); singleViewExpanded = true; } } }; </code></pre> <p>singleViewExpanded lets you track whether you are showing all views or just one. The onClickListener is defined here so that we can set it for each of the TextViews.</p> <p>These are the show and hide methods:</p> <pre><code> private void showAllViews() { tv1.setVisibility(View.VISIBLE); tv2.setVisibility(View.VISIBLE); tv3.setVisibility(View.VISIBLE); tv4.setVisibility(View.VISIBLE); tv5.setVisibility(View.VISIBLE); } private void hideAllViews() { tv1.setVisibility(View.GONE); tv2.setVisibility(View.GONE); tv3.setVisibility(View.GONE); tv4.setVisibility(View.GONE); tv5.setVisibility(View.GONE); } </code></pre> <p>And finally, wire up the onClick handlers inside onCreate method:</p> <pre><code>tv1 = (TextView)findViewById(R.id.textview1); tv2 = (TextView)findViewById(R.id.textview2); tv3 = (TextView)findViewById(R.id.textview3); tv4 = (TextView)findViewById(R.id.textview4); tv5 = (TextView)findViewById(R.id.textview5); tv1.setOnClickListener(myOnClickListener); tv2.setOnClickListener(myOnClickListener); tv3.setOnClickListener(myOnClickListener); tv4.setOnClickListener(myOnClickListener); tv5.setOnClickListener(myOnClickListener); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload