Android: Inflate View under a View then slide top view off -


my issue have main screen, , dynamically spawn view under button click, slide main view off screen revealing view below it. i've accomplished this, feel there's got better way. way i've done limited in can't spawn views on , on again under main.

my main xml file looks this:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" >   <relativelayout     android:id="@+id/subpage"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >   </relativelayout>   <relativelayout     android:id="@+id/homescreen"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <relativelayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:background="@drawable/homebg"         >     </relativelayout>   </relativelayout> </relativelayout> 

i've deleted unnecessary stuff. what's important. notice first child of main layout relative layout id "subpage." use java inflate layout subpage layout when button clicked animate "homescreen" layout off screen. seems shouldn't have have subpage declared in advance though. guess question is, there way dynamically declare new child layout underneath existing layout?

=======================================================================

edit: part 2 of question

i'm trying use addview , app crashes. code use try add view , inflate xml it. in code below subview viewgroup because understand can inflate viewgroups, not regular views. 'activity' defined @ top of class 'private activity activity = this'. ideas causing crash?

btnhelp.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             subview = (viewgroup)new view(getapplicationcontext());             mainscreen.addview(subview,1);             layoutinflater inflater = activity.getlayoutinflater();             inflater.inflate(r.layout.help, subview);         }     }); 

=======================================================================

edit: part 3 of question

so 1 more issue. works great far inflating , sliding off. however, view inflated has button in it. i'm trying assign listener button, doesn't seem work. i'm doing adding listener button after layout inflater called in btnhelp i've been working on. here's code:

btnhelp.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             layoutinflater inflater = activity.getlayoutinflater();             mainscreen.addview(inflater.inflate(r.layout.help, null),0);             homescrn.startanimation(slideleftout);             btnbackhome = (imageview)findviewbyid(r.id.backmenubtn);             btnbackhome.setonclicklistener(gohome);          }     }); 

gohome handler i've defined below such:

private onclicklistener gohome = new onclicklistener(){     public void onclick(view v) {         log.d("clickevent: ","btnbackhome clicked");         homescrn.startanimation(sliderightin);     } }; 

when click button referenced btnbackhome doesn't anything. i'm not sure if it's because listener isn't being assigned, keeping button being clicked, or else.

call addview() on relativelayout add children it, children either inflated (getlayoutinflater().inflate()) or constructed directly in java.

also, might consider using viewflipper, considering you're seeking (animated transition child child, 1 child visible @ time in steady state), perhaps less code.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -