Note that there are some explanatory texts on larger screens.

plurals
  1. POmanaging visibility of relativelayout children
    primarykey
    data
    text
    <p>I had to implement the expand/collapse(show/hide) a particular view on click of a some other view..Finally got it working but with a small problem.<br> I have a relative layout with two children: first is the textview and second is a linear layout.<br> On the click event of the textview i set the visibility(VISIBLE or GONE) of the following linear layout.<br> Now the problem is that after the linear layout is visible it somehow manages to hide the textview..<br> I tried <code>textview.bringToFront()</code> but it just makes the textview overlap the first row of the linearlayout ie the textview comes on top of the linear layout content.<br> I tried putting the textview in a linearlayout, but it makes no difference.<br> I tried setting the linear layout as BELOW. All in vain..<br> I know the textview exists because when i click the first row(which is overlapping the textview) the click event gets fired..<br> All i want is that no matter what my textview should be visible and the linear layout must take its position below the textview if it is visible..<br> <strong>EDIT</strong> </p> <pre><code>RelativeLayout wrapperlayout = new RelativeLayout(getActivity()); //wrapperlayout.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT)); //-------------HANDLE--------------------------- TextView txtHeader = new TextView(getActivity()); txtHeader.setOnClickListener(new OnClickListener() { @SuppressLint("NewApi") @Override public void onClick(View v) { // TODO Auto-generated method stub TextView tv = (TextView) v; RelativeLayout rParent = (RelativeLayout) tv.getParent(); LinearLayout lInner = (LinearLayout) rParent.getChildAt(1); if(lInner.isShown()) { tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.expand, 0, 0, 0); //tv.bringToFront(); lInner.setVisibility(View.GONE); //lInner.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up)); } else{ tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.collapse, 0, 0, 0); //tv.bringToFront(); lInner.setVisibility(View.VISIBLE); lInner.setTop(tv.getBottom()); //lInner.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.slide_down)); } } }); txtHeader.setText("Header"); txtHeader.setCompoundDrawablesWithIntrinsicBounds(R.drawable.expand, 0, 0, 0); txtHeader.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT)); //--------------CONTENT------------------------- LinearLayout lContent = new LinearLayout(getActivity()); lContent.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT)); lContent.setOrientation(LinearLayout.VERTICAL); HashMap&lt;String, String&gt; MySet = new HashMap&lt;String, String&gt;(); MySet = getData(); Iterator&lt;String&gt;RowItr = MySet.keySet().iterator(); int rowcnt = 0; while (RowItr.hasNext()) { LinearLayout lRow = new LinearLayout(getActivity()); LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); lRow.setLayoutParams(lparams1); lRow.setOrientation(LinearLayout.HORIZONTAL); TextView txtLbl = new TextView(getActivity()); txtLbl.setLayoutParams(new LinearLayout.LayoutParams(0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1)); TextView txtVal = new TextView(getActivity()); txtVal.setLayoutParams(new LinearLayout.LayoutParams(0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1)); String Lbl = RowItr.next(); txtLbl.setText(Lbl); if(rowcnt % 2 != 0) lRow.setBackgroundColor(Color.parseColor("#dbe4f0")); else lRow.setBackgroundColor(Color.parseColor("#ffffff")); txtVal.setText(MySet.get(Lbl)); lRow.addView(txtLbl); lRow.addView(txtVal); lRow.setPadding(10, 10, 10, 10); lContent.addView(lRow); rowcnt++; } lContent.setVisibility(View.GONE); wrapperlayout.addView(txtHeader); wrapperlayout.addView(lContent); RelativeLayout.LayoutParams rPARAMS = new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); //rPARAMS.addRule(RelativeLayout.ABOVE, txtHeader.getId()); //rPARAMS.addRule(RelativeLayout.BELOW, lContent.getId()); wrapperlayout.setLayoutParams(rPARAMS); </code></pre>
    singulars
    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