Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:43:22+00:00 2026-06-01T03:43:22+00:00

in trying to streamline my code for the UI for the game I’m developing,

  • 0

in trying to streamline my code for the UI for the game I’m developing, I found it very worth while to try passing a RelativeLayout through onClick() of an ImageButton.

I was wondering if this is possible because it seems to be force closing whenever the ImageButton is clicked? Is this a problem with my code in general, or is the actual mechanism of passing through the RelativeLayout impossible?

Thanks in Advanced,
Here is my code:

public class SecondaryMenu extends Activity {

    ImageButton scrambledbutton; //Button That checks click and performs animation for the scrambled carton.
    ImageButton breakfastburritobutton; //Button for animation for breakfast burrito carton.
    ImageButton eggsbenedictbutton; //Button for eggs benedict carton animation.
    ImageButton eggsontoastbutton; //Button for eggs on toast animation
    ImageButton eggsaladsandwichbutton; //Button for egg salad sandwich animation.
    ImageButton eastereggsbutton; //Button for easter eggs animation.
    ImageButton ostricheggsbutton; //Button for ostrich eggs animation.
    ImageButton quaileggsbutton; //Button for quail eggs animation.
    RelativeLayout animatedcarton; //RelativeLayout for animating

    public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.secondary_menu); //Sets the current layout to the Secondary_Menu layout


           //Does animation based on button press - SCRAMBLED
           scrambledbutton = (ImageButton) findViewById(R.id.scrambledbutton); 
           scrambledbutton.setOnClickListener(new View.OnClickListener() { 

                @Override
                public void onClick(View v) {               

                    //Calls the animation for the carton, and passes it the view to animate.
                    cartonanimation(findViewById (R.id.scrambledcarton));
                }
           });

           //Does animation based on button press - BREAKFAST BURRITO
           breakfastburritobutton = (ImageButton) findViewById (R.id.breakfastburritobutton);
           breakfastburritobutton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    //Calls animation and passes view to be animated.
                    cartonanimation(findViewById (R.id.breakfastburittocarton));                
                }
           });

    }

    //Animation that slides clicked carton off the screen
    private void cartonanimation(View tempview) {
        animatedcarton = (RelativeLayout) tempview;
        animatedcarton.setVisibility(RelativeLayout.VISIBLE);
        animatedcarton.setBackgroundResource(R.anim.secondarymenuanimation);
        AnimationDrawable viewAnimation = (AnimationDrawable) animatedcarton.getBackground();
        viewAnimation.start();
        viewAnimation.setOneShot(true);
    }
}

And my xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="320dp"
android:layout_height="wrap_content" 
android:gravity="top">

<!-- Carton number 1 - Scrambled -->
<RelativeLayout
  android:orientation="vertical"
  android:layout_width="320dp"
  android:layout_height="160dp" 
  android:gravity="top"
  android:id="@+id/scrambledcarton">
    <ImageButton 
        android:id="@+id/scrambledbutton" 
        android:background="@drawable/cartonbackground" 
        android:layout_centerVertical="true" 
        android:layout_centerHorizontal="true" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginBottom="20dp">
    </ImageButton>
    <TextView 
        style="@style/cartondishstyle"
        android:text="@string/carton1"><!-- Change for each Carton -->
    </TextView>
    <TextView
        style="@style/cartoneggcountstyle" 
        android:text="18"
        android:layout_marginRight="40dp"><!-- Adjust for each Carton -->
    </TextView>
</RelativeLayout>

<!-- Carton number 2 - Breakfast Burrito -->
<RelativeLayout
  android:orientation="vertical"
  android:layout_width="320dp"
  android:layout_height="160dp" 
  android:gravity="top"
  android:id="@+id/breakfastburittocarton">
    <ImageButton 
        android:id="@+id/breakfastburritobutton" 
        android:background="@drawable/cartonbackground" 
        android:layout_centerVertical="true" 
        android:layout_centerHorizontal="true" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginBottom="20dp">
    </ImageButton>
    <TextView 
        style="@style/cartondishstyle"
        android:text="@string/carton2"><!-- Change for each Carton -->
    </TextView>
    <TextView
        style="@style/cartoneggcountstyle" 
        android:text="18"
        android:layout_marginRight="40dp"><!-- Adjust for each Carton -->
    </TextView>
</RelativeLayout>

</LinearLayout>

And the Log Cat

04-02 00:27:24.725: ERROR/AndroidRuntime(1674): FATAL EXCEPTION: main

04-02 00:27:24.725: ERROR/AndroidRuntime(1674): android.content.res.Resources$NotFoundException: File res/anim/secondarymenuanimation.xml from drawable resource ID #0x7f040000

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.content.res.Resources.loadDrawable(Resources.java:1697)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.content.res.Resources.getDrawable(Resources.java:581)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.view.View.setBackgroundResource(View.java:7533)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at com.example.eggRoll.SecondaryMenu.cartonanimation(SecondaryMenu.java:54)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at com.example.eggRoll.SecondaryMenu.access$0(SecondaryMenu.java:51)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at com.example.eggRoll.SecondaryMenu$1.onClick(SecondaryMenu.java:35)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.view.View.performClick(View.java:2485)
04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.view.View$PerformClick.run(View.java:9080)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.os.Handler.handleCallback(Handler.java:587)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.os.Handler.dispatchMessage(Handler.java:92)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.os.Looper.loop(Looper.java:123)
04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.app.ActivityThread.main(ActivityThread.java:3683)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at java.lang.reflect.Method.invokeNative(Native Method)
04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at java.lang.reflect.Method.invoke(Method.java:507)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at dalvik.system.NativeStart.main(Native Method)
04-02 00:27:24.725: ERROR/AndroidRuntime(1674): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag set

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:783)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     at android.content.res.Resources.loadDrawable(Resources.java:1694)

04-02 00:27:24.725: ERROR/AndroidRuntime(1674):     ... 16 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:43:23+00:00Added an answer on June 1, 2026 at 3:43 am

    You might have to put viewAnimation.setOneShot(true); before viewAnimation.start(); since it would effect how it is played.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to streamline large chunk of legacy C code in which, even today,
I am trying to streamline my code. I have a 2-column array from which
I am trying to streamline a complex process of storing information in multiple tables
In order to reduce repetition and streamline testing/debugging, I'm trying to find the best
I'm trying to enjoy some of the awesome javascript code golf submissions on anarchy
I'm trying to streamline the installation of a package that requires a registry change
I'm trying to develop code for mpeg/h.264/RTP streaming. I'm quite new to all this
I'm trying to test some streaming file upload/download code that I've just written, but
I am trying to use the Streaming API from php, I use the code
I'm trying to debbug my actionscript (AS3) code on Client side that works with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.