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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:39:24+00:00 2026-06-02T09:39:24+00:00

When i went through couple of android examples, in that i find some values

  • 0

When i went through couple of android examples, in that i find some values are hard coded,

For eg:

<ImageView
    android:id="@+id/icon"
    android:layout_width="22px"
    android:layout_height="22px"
    android:layout_marginLeft="4px"
    android:layout_marginRight="10px"
    android:layout_marginTop="4px"
    android:src="@drawable/ic_launcher" >
</ImageView>

In this image view values are hard coded, for my custom layout.. how to avoid these kinds of hard coding?
Is this the correct way in android?, does it have any impact on various screen size devices?

  • 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-02T09:39:25+00:00Added an answer on June 2, 2026 at 9:39 am

    You need to read some developer docs:

    http://developer.android.com/guide/practices/screens_support.html
    http://developer.android.com/guide/practices/screens_support.html#screen-independence

    NO:

    <ImageView
        android:id="@+id/icon"
        android:layout_width="22px"
        android:layout_height="22px"
        android:layout_marginLeft="4px"
        android:layout_marginRight="10px"
        android:layout_marginTop="4px"
        android:src="@drawable/ic_launcher" >
    </ImageView>
    

    Above will not scale well across screens

    Yes:

    <ImageView
        android:id="@+id/icon"
        android:layout_width="22dip"
        android:layout_height="22dip"
        android:src="@drawable/ic_launcher" >
    </ImageView>
    

    Above will scale its pixels ‘independently’ per device

    or

    <ImageView
        android:id="@+id/icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" >
    </ImageView>
    

    Above will draw itself relative to the screen size

    or

    <ImageView
        android:id="@+id/icon"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="22dip"
        android:src="@drawable/ic_launcher" >
    </ImageView>
    

    Above will draw itself relative to the screen size and the other views on the screen

    or

    ImageView imageView = new ImageView(this);
            imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            imageView.setImageDrawable(R.drawable.background);
    
            layout.addView(imageView);
    

    Above is created programmatically

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

Sidebar

Related Questions

I went through couple of articles that talk about Web Workers in HTML5 and
I just went through a spring transaction tutorial which mentions that there are some
I went through some tutorials, and in the Android Doc, it says not to
I went through a document at Adobe Livedocs that describes working with pdf: http://livedocs.adobe.com/flex/3/html/help.html?content=PDF_1.html
I went through some tutorials on the State monad and I think I got
I went through answers on similar topics here on SO but could't find a
I went through many posts and couldn't find a solution. (I came across with
I have went through couple of questions already asked related with this and i
I went through a few blogs/posts and there are some good solutions for input
I went through a java tutorial that allowed me to create a text file

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.