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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:07:28+00:00 2026-05-27T10:07:28+00:00

I have LinearLayout in my xml file that I am trying to add a

  • 0

I have LinearLayout in my xml file that I am trying to add a custom view to. Here is my xml code:

        <LinearLayout android:id="@+id/amenitycontent"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/background_color">

            <com.mypackage.util.AmentiesView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </LinearLayout>

This code is inside a TabHost (not sure if this makes a difference).

and here is my custom view:

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class AmentiesView extends View{

Bitmap image;
String title;
private final Paint paint = new Paint();

public AmentiesView(Context context) {
    super(context);
    image = BitmapFactory.decodeResource(getResources(), R.drawable.checkcircle);

}
public AmentiesView(Context context, AttributeSet attrs) {
    super(context, attrs);
    image = BitmapFactory.decodeResource(getResources(), R.drawable.checkcircle);

}

public void setTitle(String _title){
    title = _title;
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawBitmap(image, 0, 0, paint);
    canvas.drawText(title, image.getWidth() + 10, 0, paint);
    canvas.drawColor(Color.RED);
}


}

When I run the code, nothing is shown. Any ideas?

  • 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-27T10:07:28+00:00Added an answer on May 27, 2026 at 10:07 am

    Try setting some fixed numbers for width and height of your view – i.e 300×200. There’s a good chance that since you’re setting the width and height to wrap_content and your view basically has no content(nothing added in it) the canvas you’re getting in onDraw is empty.

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

Sidebar

Related Questions

In my .xml file i have this format: <LinearLayout android:layout_orientation=vertical...> <ImageView>... </ImageView> <ScrollView ...>
I have a LinearLayout view that I am trying to add a divider to
I have the following XML layout file, HELPME.XML <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
Trying to create a custom component that gets it's layout from an XML file
i have been trying to create an xml file that integrates a relative layout
i have customview, i want to add that in the xml file i tried
I wanna use custom font file. For that below is my code XML file:
Say I have a LinearLayout with some elements in it as an .xml file.
I have the following XML: <LinearLayout android:id=@+id/linearLayout1 android:layout_width=fill_parent android:layout_height=wrap_content > <TextView android:id=@+id/tv1 android:layout_width=wrap_content android:layout_height=wrap_content
I have the following XML layout for a ListActivity. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

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.