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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:11:34+00:00 2026-05-18T01:11:34+00:00

I started a test project just to get this down. No changes to main.xml.

  • 0

I started a test project just to get this down. No changes to main.xml. I want to create a widget-sized ImageView (80×100) that contains a Bitmap converted from a TextView. Yes, that sounds very roundabout but this is just for testing; in the end I want the ImageView to have a background image and multiple TextViews. I’m not sure exactly what I’m doing wrong, but nothing is being pushed to the screen.

Is it a problem with declaring the TextView/ImageView and passing it “this” in the constructor? Is it a problem with my layoutParams? Here is the code:

package com.doaf.testproject;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TestProject extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView tv = new TextView(this);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
        tv.setLayoutParams(layoutParams);
        tv.setText("testing 1 2 3");
        tv.setTextColor(0xFFFFFF);
        tv.setBackgroundColor(0x555555);

        Bitmap testB;
        testB = loadBitmapFromView(tv);

        ImageView iv = new ImageView(this);
        iv.setLayoutParams(layoutParams);
        iv.setBackgroundColor(0x555555);
        iv.setImageBitmap(testB);

        setContentView(iv);
    }

    public static Bitmap loadBitmapFromView(View v) {
        Bitmap b = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.layout(0, 0, 80, 100);
        v.draw(c);
        return b;
    }
}

Thanks for any help you can provide. I’m relatively new to Android, and pretty lost with this one.

  • 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-18T01:11:35+00:00Added an answer on May 18, 2026 at 1:11 am

    I believe its taking up the whole screen because you don’t have a container such as a Linear Layout which then contains an ImageView with layout constraints, so the ImageView expands to fill the available screen. Try this:

    @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            TextView tv = new TextView(this);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
            tv.setLayoutParams(layoutParams);
            tv.setText("testing 1 2 3");
            tv.setTextColor(Color.BLACK);
            tv.setBackgroundColor(Color.TRANSPARENT);
    
            Bitmap testB;
    
            testB = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(testB);
            tv.layout(0, 0, 80, 100);
            tv.draw(c);
    
            ImageView iv = (ImageView)findViewById(R.id.menuIcon);
            iv.setLayoutParams(layoutParams);
            iv.setBackgroundColor(Color.GRAY);
            iv.setImageBitmap(testB);
            iv.setMaxHeight(80);
            iv.setMaxWidth(80);
        }
    

    And in your main.xml file:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    
        <ImageView android:id="@+id/menuIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    
    </LinearLayout>
    

    I’m not sure what you want to achieve, but I’m sure there are more efficient ways of approaching it.

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

Sidebar

Related Questions

How would you test this scenario? I've just started looking into NHibernate and having
Just some days ago I started looking into a unit test framework called check,
We started using memcached on the test server for our social media project and
I've started to look into the whole unit testing/test-driven development idea, and the more
I started a Rails project recently and decided to use RESTful controllers. I created
Just started getting a bunch of errors on our C# .Net app that seemed
I am building a scala web project using scala test, lift, jpa, hibernate, mercurial
I am just getting started with Jetty (Jetty 6 w/ Java 6). Using the
I'm using the NUnit GUI version, and it started to get upset at me
I want to test an application which renders a text block with a data

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.