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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:50:42+00:00 2026-06-10T17:50:42+00:00

I have an Android application, and i want to store some generic view attributes

  • 0

I have an Android application, and i want to store some generic view attributes (primarily width and height) in a separate XML file (values.xml). An example:

<Button
    android:id="@+id/button1"
    android:layout_width="@strings/genericbuttonwidth"
    android:layout_height="wrap_content"
    android:text="Button" />

with the res/values/strings.xml looking like:

<resources>
    <string name="genericbuttonwidth">50dp</string>
</resources>

The Eclipse graphical layout viewer makes the width 50dp, as given in strings.xml, but when ran on an Android (physical) device, it throws an exception:

Caused by: java.lang.RuntimeException: Binary XML file line #174: You must supply a layout_width attribute.

So what I am trying to do doesn’t really work (when I replace the the reference with 50dp, it works nicely). Any way or workaround to load the attributes from a separate XML file?

  • 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-10T17:50:43+00:00Added an answer on June 10, 2026 at 5:50 pm

    XML file saved at res/values/dimens.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <dimen name="textview_height">25dp</dimen>
        <dimen name="textview_width">150dp</dimen>
        <dimen name="ball_radius">30dp</dimen>
        <dimen name="font_size">16sp</dimen>
    </resources>
    

    This application code retrieves a dimension:
    Resources res = getResources();
    float fontSize = res.getDimension(R.dimen.font_size);
    This layout XML applies dimensions to attributes:

    <TextView
        android:layout_height="@dimen/textview_height"
        android:layout_width="@dimen/textview_width"
        android:textSize="@dimen/font_size"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have Some Android Application On Google Play Store Of Version GingerBread.Many Users Install
I have created an android application where user need to login to store some
I have an Android application with a Spinner and want to fill it dynamically
I have an android application and while switching between two activities I want to
I have an android application and web-server working together. Now I want user log
I have been developing Android application for Android 3.x and now I want to
I am developing an android application in which i have a local database.I want
i have a problem with my Android Application. The Error occures when i want
I want to integrate the zxing source code to my Android application. I have
I have build my very first application to Android and I want now to

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.