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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:56:01+00:00 2026-06-09T21:56:01+00:00

I have a customm view which generates an arc and i’ve put in the

  • 0

I have a customm view which generates an arc and i’ve put in the xml like this

<com.example.application.ArcView
        android:id="@+id/arcView1"
        android:layout_width="@string/arc_size"
        android:layout_height="@string/arc_size"
        android:layout_centerInParent="true" />

I have the height and width that change based on the screen density

I’ve coded it like this but it doesn’t work

Resources res = getResources();
    String arcSizeString = res.getString(R.string.arc_size);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    switch(metrics.densityDpi){
         case DisplayMetrics.DENSITY_LOW:
             arcSize = 170;
             arcSizeString = (arcSize + "px");
                    break;
         case DisplayMetrics.DENSITY_MEDIUM:
             arcSize = 227;
             arcSizeString = (arcSize + "px");
                     break;
         case DisplayMetrics.DENSITY_HIGH:
             arcSize = 342;
             arcSizeString = (arcSize + "px");
                     break;
    }       

How can i set the width and height to a variable?

  • 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-09T21:56:03+00:00Added an answer on June 9, 2026 at 9:56 pm

    Probably, You want to ask ‘how to set width and height to View’.

    You need to reference instance of ArcView in your Activity class, to be more precise in onCreate method of Activity like this :

    ArcView arcView = (ArcView)findViewById(R.id.arcView1);
    

    Afther that, calculate width and height based on density and set it to your view via

    arcView.setLayoutParams(myLayoutParams);
    

    LinearLayout.LayoutParams

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

Sidebar

Related Questions

I have a custom view which has a piano keyboard drawn inside of it.
Please help me to turn off user interaction. I have a custom view which
In my custom View which I have added to my viewControllers's view, I need
I have two helper methods inside a custom View which are called by their
I have a view with two subviews: A UIImageView A small Custom View which
I have a custom view with several NSTextField controls for which I want to
I have a GridView in which each row has a custom view. The grid
I have view on which I defined a custom tagName. I need to be
I have a custom component which consists of 2 text view and 4 toggle
I have a custom View that I would like to embed in an WebView.

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.