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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:05+00:00 2026-05-23T03:26:05+00:00

I am drawing a custom view in my application which basically takes arguments(XML) as

  • 0

I am drawing a custom view in my application which basically takes arguments(XML) as the text to display and then keeps on rotating it infinitely.

While I was making this control I had a few doubts which I want to ask:

  • I have made 2 of my stylable attributes which I have declared in the attrs.xml file. These attributes are to set the width and the width of the circle used in my control. These values I would use in the ondraw method and the onmeasure method. I ran my program by declaring just these but there was an error which asked me to put android:width and android:height attributes. My question is why would I need those if I am already using my custom attributes to define the height and the width of my view

  • I am coding on a mac. Now when I was making my attrs.xml file, to get the autocomplete list which we usually get by ctrl+space was not showing up. Why is that. For e.g., i wanted to know what values can I give the format attribute of my custom attribute that like I am demostrating in the following:
    <attr name ="somename" format="value I wanted to find out through autocomplete"> . Why is the autocomplete not popping up? It does pop up when I am making a.java file.

  • In my ondraw() method I wanted to draw a circle. Now for this I would require the co-ordinates of the center of the circle. So what I do is put 0, 0. But this is not correct. I want the circle to be at the center of the parent view it is in. So if my view is in a hierarchy I want it to respect that. I want to give the co-ordinates relative to the parent view. What is happeining right now is that it is being drawn at the top left corner of my screen. This is what I don’t want. What do I do to achieve this?

  • 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-23T03:26:06+00:00Added an answer on May 23, 2026 at 3:26 am

    why would I need those if I am already using my custom attributes to define the height and the width of my view?

    This is because Android needs to know how and where to put your view in the layout. You can implement your view to make use of your custom height/width requirements by overriding View.onMeasure() to return your own size parameters. You can then just set android:layout_width="wrap_content" android:layout_height="wrap_content" in your layout file.

    Why is the autocomplete not popping up? It does pop up when I am making a.java file.

    Autocomplete and autodoc implementation for Android xml files is shaky at best, so it’s not really surprising that it doesn’t work. I’m not aware of a fix and AFAIK it’s an IDE bug.

    In my ondraw() method I wanted to draw
    a circle. Now for this I would require
    the co-ordinates of the center of the
    circle. So what I do is put 0, 0. But
    this is not correct. I want the circle
    to be at the center of the parent view
    it is in. So if my view is in a
    hierarchy I want it to respect that. I
    want to give the co-ordinates relative
    to the parent view. What is happeining
    right now is that it is being drawn at
    the top left corner of my screen. This
    is what I don’t want. What do I do to
    achieve this?

    If you implemented onMeasure() correctly, the coordinates relative to parent should be taken care of already. To get the center of your view use the following code:

    void onDraw(Canvas canvas)
    {
    int centerX = this.getWidth() / 2;
    int centerY = this.getHeight()) / 2;
    //..draw code here
    }
    

    Edit
    Here’s an example with source code that should help: http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

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

Sidebar

Related Questions

I have a view that I want to add some custom drawing to. I
I am writing an iPhone application in Objective-C that utilizes some custom drawing in
I'm trying to draw a custom border by drawing a custom view. Here is
I am trying to move some custom drawing code from a view into a
I my outline view, i am adding Custom cell, To drawing custom cell, i
I required a custom tab-switching view for my application, so i made a .xib
I have a drawing activity that creates a custom 'canvas' View that occupies the
I'm doing custom drawing in datagridview cells and I have items that can vertically
I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the
System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml

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.