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 6749619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:42:42+00:00 2026-05-26T12:42:42+00:00

I’m new to Android app development and I would like to ask something. I

  • 0

I’m new to Android app development and I would like to ask something.

I have a bitmap inside my SurfaceView that I want to animate and move programmatically. I also want to put a button in the screen to control the moving of the bitmap. But since I cannot put a button in a SurfaceView, I declared it inside a RelativeLayout in my XML layout called main.xml.

Here’s what’s inside my main.xml

<?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"
    android:id="@+id/main_layout" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Test Button" />

</RelativeLayout>

So what I’m trying to do is to “combine” (can’t find a better word) the SurfaceView with the Layout that is in my main.xml.

Here is my Main.java where I try to combine the Layout w/ the SurfaceView

package com.src.test.view;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RelativeLayout;

public class Main extends Activity {

    private RelativeLayout _myXmlLayout;
    private MyView _myView;
    private Button _myButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        _myXmlLayout = (RelativeLayout) findViewById(R.id.main_layout);
        _myView = new MyView(this);
        _myButton = (Button) findViewById(R.id.button1);

        _myXmlLayout.addView(_myButton);
        _myXmlLayout.addView(_myView);

        setContentView(_myXmlLayout);
    }
}

but it gives me an “application has stopped unexpectedly” error. Am I doing it wrong? If so, can you suggest a better way of implementing this?

Your response is highly appreciated. Thanks!

p.s. no bitmap animation codes and button controls yet. It’s just the views that I’m currently solving. 🙂

EDIT:

I edited my codes and here it is:

so here’s my edited Main.java

package com.src.test.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

    }
}

and here’s my main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.src.test.view.MyView
        android:id="@+id/myView" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <Button
        android:text="Test Button"
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left" />
    <Button
        android:text="Test Button2"
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right" />

</FrameLayout>

I tried to run it but it gives me an error.

Here’s the logcat

(ZygoteInit.java:626)
10-29 01:18:51.046: E/AndroidRuntime(318):  at dalvik.system.NativeStart.main(Native Method)
10-29 01:18:51.046: E/AndroidRuntime(318): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.src.test.view.MyView
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.createView(LayoutInflater.java:503)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-29 01:18:51.046: E/AndroidRuntime(318):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.app.Activity.setContentView(Activity.java:1647)
10-29 01:18:51.046: E/AndroidRuntime(318):  at com.src.test.view.Main.onCreate(Main.java:12)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-29 01:18:51.046: E/AndroidRuntime(318):  ... 11 more
10-29 01:18:51.046: E/AndroidRuntime(318): Caused by: java.lang.NoSuchMethodException: MyView(Context,AttributeSet)
10-29 01:18:51.046: E/AndroidRuntime(318):  at java.lang.Class.getMatchingConstructor(Class.java:660)
10-29 01:18:51.046: E/AndroidRuntime(318):  at java.lang.Class.getConstructor(Class.java:477)
10-29 01:18:51.046: E/AndroidRuntime(318):  at android.view.LayoutInflater.createView(LayoutInflater.java:475)
10-29 01:18:51.046: E/AndroidRuntime(318):  ... 21 more

Thank you for your response

  • 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-05-26T12:42:43+00:00Added an answer on May 26, 2026 at 12:42 pm

    I think you are overcomplicating this for yourself. At least, to simply put a button over a SurfaceView, visually, you can do something like what is shown here, by putting the button in the same FrameLayout as the surface view.

    You can declare your custom view in xml as well, so it could look like:

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <com.src.test.view.MyView android:id="@+id/myView" android:layout_width="fill_parent" android:layout_height="fill_parent" />
        <Button android:text="Button" android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </FrameLayout>
    

    then in onCreate you only have to say

    setContentView(R.layout.main_layout);
    

    You can position the button wherever you wish, for example if you want it to be in the bottom center, use android:layout_gravity="bottom|center_horizontal".

    EDIT:

    To make sure that your custom view implements all the necessary constructors (some of which are called when views are created from xml), open your custom view class in the eclipse editor, and go to the menu Source -> Generate Constructors from Superclass…

    It will help you create constructors

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.