Monday 15 September 2014

android - FrameLayout setVisibility is not working -



android - FrameLayout setVisibility is not working -

i'm trying set framelayout view.gone along many other views in reaction screen beingness tilted landscape.

so far seems work views except 1 framelayout. not go!

i'm setting view.gone @ same time in same way other views persists:

list<view> viewstohide = getallnonfullscreenviews(); (view v : viewstohide) { v.setvisibility(view.gone); }

i've check view beingness found , set gone individually. i've called clearanimation() because animate @ 1 point , i've heard issue.

view dropdowncontainer = getactivity().findviewbyid(r.id.dropdowncontainerview); dropdowncontainer.clearanimation(); dropdowncontainer.setvisibility(view.gone);

i've tried set gone individually on ui thread. 1 time again setting breakpoints , making sure view found , set gone.

getactivity().runonuithread(new runnable() { @override public void run() { view dropdowncontainer = getactivity().findviewbyid(r.id.dropdowncontainerview); dropdowncontainer.clearanimation(); dropdowncontainer.setvisibility(view.gone); } });

i've tried same thing 1 time again after delay

new handler().postdelayed(new runnable() { @override public void run() { view dropdowncontainer = getactivity().findviewbyid(r.id.dropdowncontainerview); dropdowncontainer.clearanimation(); dropdowncontainer.setvisibility(view.gone); } }, 3000);

what's particularly unusual when check view after delay, set gone?! can still see on screen. it's right view because if set gone straight away , not in reaction anything, view go away expected.

new handler().postdelayed(new runnable() { @override public void run() { //check dropdown view dropdown = getactivity().findviewbyid(r.id.dropdowncontainerview); int visibility = dropdown.getvisibility(); if (visibility == view.visible) { log.d("dropdown", "is visible"); } else if (visibility == view.invisible) { log.d("dropdown", "is invisible"); } else if (visibility == view.gone) { log.d("dropdown", "is gone"); //runs } } }, 4000); edit: xml

i'm inserting framelayout programatically in view.

so "parent" view.

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/containerframe"> <linearlayout android:id="@+id/detailbg" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/detail_bg" android:orientation="vertical" > <linearlayout android:orientation="vertical" android:id="@+id/dropdowncontainer" android:layout_width="fill_parent" android:layout_height="48dp"> </linearlayout> <view android:id="@+id/detailspacer" android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/light_gray" /> <linearlayout android:id="@+id/detailcontainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" /> </linearlayout> </framelayout>

the view i'm trying hide:

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dropdowncontainerview" android:layout_width="fill_parent" android:layout_height="fill_parent"> <relativelayout android:id="@+id/selectedview" android:layout_width="fill_parent" android:layout_height="48dp" android:background="#ffffff"> <view android:id="@+id/grayline1" android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparenttop="true" android:background="@color/light_gray" /> <view android:id="@+id/grayline2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/light_gray" /> <textview android:id="@+id/selectedtext" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:paddingleft="20dp" android:layout_centervertical="true" android:gravity="center" android:textsize="18sp" android:textcolor="#0081c8"/> </relativelayout> </framelayout>

and i'm adding so:

framelayout parentframe = (framelayout) getactivity().findviewbyid(r.id.containerframe); dropdownview = new dropdownview(getactivity(), options, 0, this); parentframe.addview(dropdownview, 1); edit: animation

as mentioned, view i'm trying hide can animated in response tap. although view still won't disappear if animation never run begin with. here animation code:

final boolean shouldopen = !isdropdownshowing; relativelayout selectionview = (relativelayout) findviewbyid(r.id.selectedview); final int listheight = dropdownlistview.getheight(); final int heightofselectionview = selectionview.getheight(); translateanimation translateanimation; if (shouldopen) { translateanimation = new translateanimation (0.0f, 0.0f, heightofselectionview - listheight, 0); int y = heightofselectionview; dropdownlistview.sety(y); } else { translateanimation = new translateanimation (0.0f, 0.0f, 0, 0 - listheight); } translateanimation.setfillafter(true); translateanimation.setfillenabled(true); translateanimation.setduration(300l); translateanimation.setrepeatcount(0); translateanimation.setanimationlistener(new animation.animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation animation) { if (shouldopen) { isdropdownshowing = true; dropdownlistview.sety(heightofselectionview); } else { isdropdownshowing = false; dropdownlistview.sety(0 - listheight); } dropdownlistview.clearanimation(); } @override public void onanimationrepeat(animation animation) { } }); dropdownlistview.startanimation(translateanimation);

i think you're setting visibility of framelayout , not navigating on kid views , setting it's visibility. why other views still drawn on you're screen , framelayout beingness set gone.

to need create loop of parentview in case framelayout this:

for (int = 0; < framelayout.getchildcount(); i++) { view v = framelayout.getchildat(i); v.setvisibility(view.gone); v.postinvalidate(); }

also utilize postinvalidate refresh views. animation within loop. hope helps.

android

No comments:

Post a Comment