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

The Archive Base Latest Questions

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

I would like to design an application which could work with devices of any

  • 0

I would like to design an application which could work with devices of any screen resolution.

My idea to do so was to create one Custom View for each type of View I use, and use the layout_width and layout_height specified in the XML as a percentage of the parent size (for example, layout_width="100dp" is equivalent to fill_parent, and layout_width="50dp" means the View‘s width will be half the parent’s one).

Here is the custom TextView class I made:

public class RSTextView extends TextView {

    public RSTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int w, int h) {
        int parentWidth = ((View)this.getParent()).getWidth();
        int parentHeight = ((View)this.getParent()).getHeight();
        Log.i(null, "Width: " + w + "; Height: " + parentHeight);
        this.setMeasuredDimension(parentWidth * MeasureSpec.getSize(w) / 100,
                parentHeight * MeasureSpec.getSize(h) / 100);
    }
}

However, it does not work. The parentWidth and parentHeight size is always 0.

Is there any better way to create an application with a relative size?

And if it is the right way to go, how can I retrieve the View‘s parents’ size from the onMeasure method?

  • 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-18T10:44:08+00:00Added an answer on May 18, 2026 at 10:44 am

    Since you’re checking a view’s height during the layout phase, you probably want to be using getMeasuredHeight, not getHeight, but I’m not sure you need to be doing what you’re doing at all. It’s hard to tell from your description, but it seems like you might be trying to recreate the behavior of LinearLayout weights. For example, if you have a horizontal LinearLayout with 3 children, you can easily set the first to take up half its width and the others each to take up 25% by assigning them 0px layout_widths and layout_weights of 2, 1 and 1 respectively (or any other weights of those proportions).

    If you do decide to go the custom View route, though, don’t overload what layout_height and layout_width do — use custom XML attributes to take the argument for the percentages (I’d dig into LinearLayout‘s code to see how layout_weight is implemented).

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

Sidebar

Related Questions

We need to design a secure web application. I would like to propose a
How would you design a hosted web application? I'm looking at applications like Basecamp,
I would like to design a class template which takes an allocator type (as
I have this design which I cannot seem to get right, I would like
I would like to design a model for an online private school in Django.
I would like to design Tab Bar at bottom in HoneyComb Tablet. So, is
I would like some sugestion on how to design a table that gets like
I have an UserControl and would like to hide the resizing handles in design-time,
I have to design a GUI using Qt. I would like to draw multiple
We are in the process of nutting out the design guidelines we would like

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.