java - Android animation fade in / fade out is not setting the visibility of the view in the callback function -
i have android view want fadein , fadeout when users click on button. animation being called , callback being called when animation triggers view cannot seen. think problem xml layout, have been stuck on hours if can appreciated.
my main layout: - view in question
<linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="left|top" android:background="@color/whiteoverlay" android:gravity="center_vertical|center_horizontal" android:id="@+id/uploadoptions" android:alpha="0" android:visibility="gone"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingleft="40dp" android:paddingright="40dp"> <button style = "@style/basic_button" android:text="@string/selectfromgallery" android:id="@+id/gallery_select" android:layout_margintop="10dp" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <button style = "@style/basic_button" android:text="@string/selectfromcamera" android:id="@+id/camera_select" android:layout_margintop="10dp" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </linearlayout> </linearlayout>
fadein
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromalpha="0.0" android:toalpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" /> </set>
fadeout
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromalpha="1.0" android:toalpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" /> </set>
activity java -
public class regpp extends activity { private string lang = ""; private boolean optionsactive = false; private linearlayout options = null; private void fade (final view view, final boolean toggle){ animation anim; view.setvisibility(view.visible); if(toggle){ //fadeout anim = animationutils.loadanimation(regpp.this, r.anim.fadeout); log.d("fade","fadeout"); } else { //fadein anim = animationutils.loadanimation(regpp.this, r.anim.fadein); log.d("fade","fadein"); } view.startanimation(anim); anim.setanimationlistener(new animation.animationlistener(){ @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation arg0) { //functionality here if(toggle){ view.setvisibility(view.gone); log.d("fade", "fadeout callback"); } else { view.setvisibility(view.visible); log.d("fade", "fadein callback"); } } @override public void onanimationrepeat(animation animation) { } }); } @override protected void oncreate (bundle savedinstancestate) { super.oncreate(savedinstancestate); this.lang = getresources().getstring(r.string.lang); strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); final context context = regpp.this; setcontentview(r.layout.reg_pp); imagebutton uploadtog = (imagebutton) findviewbyid(r.id.uploadtog); options = (linearlayout) findviewbyid(r.id.uploadoptions); uploadtog.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { fade(options,false); optionsactive = true; } }); } @override public void onbackpressed() { if(optionsactive){ fade(options,true); optionsactive = false; } else { super.onbackpressed(); } } }
remove line may u
android:visibility="gone"
visibility gone that's why view not visible
android:visibility="gone"
Comments
Post a Comment