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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:11:31+00:00 2026-05-16T06:11:31+00:00

I am unable to display both the setContentView(R.layout.main) and View together. I think I

  • 0

I am unable to display both the setContentView(R.layout.main) and View together. I think I am not getting the concept right. Could anyone explain me where I am going wrong. Thank you. //please read the comment in code

I am trying to display a image on main.xml using BitmapFactory.

   public class TryGraph extends Activity 
 {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//I think this is where I need your help
    setContentView(new myView(this));//I want this to be displayed in main.xml
}

private class myView extends View{

    public myView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sinewave);
        Bitmap resizedBitmap = Bitmap.createBitmap(myBitmap, 0, 0,
                300, 143);
        canvas.drawBitmap(resizedBitmap, 60, 50, null);
        Paint myPaint = new Paint();
        myPaint.setColor(Color.RED);
        myPaint.setStyle(Paint.Style.STROKE);
        myPaint.setStrokeWidth(5);
        canvas.drawRect(250,255,260,250, myPaint);

    }
}

}

THE XML FILE IS

  • 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-16T06:11:32+00:00Added an answer on May 16, 2026 at 6:11 am

    When you call setContentView you are telling the device to load the entire layout that should be displayed to the user. In most cases this view will occupy the entire screen. Now this Layout file is considered the root and may contain child views, one of which should be your ImageView.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView   
        android:id="@+id/banner"
        android:text="hello world"
        >  
    <ImageView
        android:id="@+id/myImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/sampleimage"
        />
    <?LinearLayout>
    

    This ImageView can now be accessed by code through the use of findViewById(R.id.myImageView) and you can then use the BitmapFactory to set your image. If the image is not going to be changed, you can just set it in the layout file android:src="@drawable/sampleimage"

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

Sidebar

Related Questions

why i am unable to display the text in my dev box? <script type=text/javascript>
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject
I am getting a Unable to load the requested file: default.php error in codeigniter
i want to display both TextBox and TextField on the screen at a time
I'm returing session data from my database, but I'm unable to display the LastName
In my view, I have a form with submit and cancel buttons. Both actions
I am writing a website code but I am unable to display the border
Unable to cast object type System.Collections.Generic.List 1[NorthwindMVC3.Models.Product] to the type ofSystem.Collections.Generic.IEnumerator 1[NorthwindMVC3.Models.Product].\ public IEnumerator<Product>
Im unable to start new project in a virtualenv. This is what i did
Error: Unable to read data from the transport connection: A blocking operation was interrupted

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.