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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:19:38+00:00 2026-06-09T07:19:38+00:00

I think the title covers it :) I have a drawable object that fetches

  • 0

I think the title covers it 🙂 I have a drawable object that fetches .png photo which I can manipulate with gestures. I also have a xml layout with a background image that is supposed to be behind this drawable object. Everything happens in a fragment.

When I run the code and get to this fragment, png is displayed and gestures work, BUT, there is no inflated layout and on back button press app crashes (I’m guessing that is because I’m using setContentView in fragment so there is no back stack? How do I avoid this?).

Later on I will add other layers to the scene.

My question is, how can I both inflate the fragment with xml layout, display drawable on top of it, and maybe later on add other views on top of all that?

Code goes like this for this fragment:

public class RoomFragment extends Fragment {

ViewGroup mRoot;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    mRoot = (ViewGroup) inflater.inflate(R.layout.room_fragment, null);

    /** Placing furniture .png element in SandboxView */
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.furniture);
    View view = new SandboxView(this.getActivity(), bitmap);
    this.getActivity().setContentView(view); // Replace with inflater?

    return mRoot;

}}

Thank you!

  • 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-09T07:19:39+00:00Added an answer on June 9, 2026 at 7:19 am

    I solved it by adding an ID in LinearLayout wrapper of this fragment, and then adding an instance of drawable view in it with addView(view) after inflating fragment with its xml.

    Fragment XML:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/bitmapBox"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/room"
        android:gravity="bottom|center"
        android:orientation="vertical" >
    </LinearLayout>
    

    Piece of fragments code:

        ViewGroup mRoot;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    
        mRoot = (ViewGroup) inflater.inflate(R.layout.room_fragment, null);
    
        /** placing furniture element in SandboxView */
        LinearLayout myLayout = (LinearLayout) mRoot
                .findViewById(R.id.bitmapBox);
    
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.furniture);
    
        View view = new SandboxView(this.getActivity(), bitmap);
    
        myLayout.addView(view);
    
        return mRoot;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Err, I can't think of better title. Basically I have a class called MarketGroups,
I don't think title is making any sense, so I hope that I can
OK, I don't think the title says it right... but here goes: I have
The title says enough I think. I have a full quality BufferedImage and I
I think the title speaks for itself. I have a complex query with a
I think the title is self-explanatory. Many times I have small typos and I
I think title says what I need. I know we can use asd function
i think the title is pretty self explanatory. I have many divs generated from
I think the title covers it all. I use the control to display some
I think the title is pretty clear. I have ran into this twice now.

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.