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

  • SEARCH
  • Home
  • 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 6683973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:53:04+00:00 2026-05-26T04:53:04+00:00

I have a class called Game that extends View. I have an xml called

  • 0

I have a class called Game that extends View. I have an xml called game.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/game_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</LinearLayout>

As you can see all it is is a LinearLayout. Now what i want to do is make my game view show up in the LinearLayout. Heres the relevent code in Game:

public Game(Activity activ)
{
    activ.setContentView(R.layout.game);

    ...

    layout = (LinearLayout)activ.findViewById(R.id.game_layout);
    layout.addView(this);

    ...
}

public void onDraw(Canvas canvas)
{
    board.draw(canvas);
}

now when i run this it is just a blank screen. What am i doing wrong? The onDraw method is fine because when i did this it worked fine:

public Game(Activity activ)
{
    activ.setContentView(this);
}

public void onDraw(Canvas canvas)
{
    board.draw(canvas);
}

but the reason why i cant do it like that anymore is because on tablets there is a bar at the bottom where the back button and the show keyboard buttons are. When i do it like this it draws under that bar and it cuts off images. If i do it like this then Android sets the bounds of the layout so that it isnt under that bar. I would prefer to do it with the xml layout anyway because I think Android works better when you use the xml layouts instead of setting your custom view to the content view. All relevent answers are appriciated!

  • 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-26T04:53:05+00:00Added an answer on May 26, 2026 at 4:53 am

    I think you are not able to see your view because you havent sepecified any layout params.
    Try this before you call addView method.

    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    layout.addView(this);
    

    The xml way of doing this would be.
    Inside you xml file you can include your custom view like

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/game_layout" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
        <com.yourpackage.Game android:layout_width="fill_parent"
            android:layout_height="fill_parent"/> 
    </LinearLayout> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called game that extends View that is added to a
I'm making a game for the iPhone, and I have a class called Robot.
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have a class called UserInfo that contains details about a given user. There
I am writing an android game. I need a Point class that stores x
I have a class called Sound.java that consists of 3 functions (initSound, addSound, and
OK so I have a code with an class object called game. Every frame
I'm creating a game that uses cards. I have an AppController class with one
I have a class called 'Items' to which 'Equips' extends from and 'Helmet' then
I have a class called Console, with the following structure: public Console(Game game) {

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.