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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:57:35+00:00 2026-06-02T01:57:35+00:00

I’m trying to figure out designing for multiple screen sizes/densities/etc. I thought dp was

  • 0

I’m trying to figure out designing for multiple screen sizes/densities/etc. I thought “dp” was my answer but it’s not working the way I thought it was going to.

Here’s what I’m trying to do:

I have a header and footer section for menu items that remain static. Then I have a ScrollView between the 2. Within the ScrollView is several “blocks” that display various information. I want those blocks to always expand to the full width of the screen. I want the height of those blocks to simply scale appropriately to keep a proper 1:1 -> height:width scale. I also want the TextViews/Images/Buttons/etc to scale and keep their position within the block. If the Blocks height get too big for the screen, that’s where the ScrollView comes in. If they fit just fine, that’s OK too. I mainly want to scale to width and let the user Scroll if necessary.

Currently if the screen gets wider, the Blocks get really wide but don’t scale the height to match them in.

Here’s a basic (simplified for readabilities sake) rundown of what my XML layout code looks like. Also note that each block may be a different size. I’m not looking for a “take up 25%” solution. The blocks have fairly complex and completely different layouts within them.

<LinearLayout>
    <RelativeLayout>Header stuff</RelativeLayout>

    <ScrollView> //height and width = match_parent width lower priority than header/footer

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="???" //Had been using a specified "dp" value but that didn't work like I thought. What goes here?
        >
                Block#1 with lots of TextViews, ImageViews and Buttons...etc
        </RelativeLAyout>

        <RelativeLayout>
                Block#2
        </RelativeLAyout>

        <RelativeLayout>
                Block#3... etc
        </RelativeLAyout>

    </ScrollView>

    <RelativeLayout>Footer stuff</RelativeLayout>

</LinearLayout>
  • 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-06-02T01:57:37+00:00Added an answer on June 2, 2026 at 1:57 am

    One way of achieving ‘perfect’ 1:1 ratio (or other predefined ratios) of a view is to create your custom extension of it and override the onMeasure() method. in your case you might want a SquareRelativeLayout with an onMeasure() method looking something like this:

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width, width);
    }
    

    Edit:
    If you want a custom ratio, you can define it somewhere and measure your View like this:

    float ratio = 0.5f;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width, ratio*width);
    }
    

    If you know how to create your own xml-attributes you can add the ratio attribute and get it from there, meaning you don’t have to create a new View for each different ratio.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.