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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:15:51+00:00 2026-06-17T22:15:51+00:00

I have a layout with a TextView and I want the android:gravity attribute value

  • 0

I have a layout with a TextView and I want the android:gravity attribute value to be pulled from another resource file, android:gravity="@???/item_align", where item_align is the name of a resource in another xml file. The typical values used in a layout, center or bottom or bottom|center_horizontal don’t work. What type goes in the @???, integer works, if I replace the strings with the actual integer value (“center” replaced with 0x011). But, that’s not a good solution.

So, the question(s): How do I refer to the value in the layout file, and what does the item look like in the resource file?

<TextView
   android:id="@+id/item_text"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentTop="true"
   android:layout_alignParentBottom="true"
   android:layout_alignParentLeft="true"
   android:layout_alignParentRight="true"
   android:layout_margin="1dp"
   android:layout_centerHorizontal="true"
   android:gravity="@???/item_align"
   android:text="65"
   android:textSize="20sp"
   android:typeface="sans"
   android:textStyle="bold"
   android:textColor="#000000" />
  • 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-17T22:15:52+00:00Added an answer on June 17, 2026 at 10:15 pm

    Concept:

     android:gravity="@integer/integer_name"
    

    integers.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <integer
            name="integer_name"
            >1</integer>
    </resources>
    

    Gravity values are all integer constanst, you have to look it up and define it in your integers.xml .

    Example implementation:

    public static final int CENTER … Constant Value: 17 (0x00000011)

    in docs… Then you add to your integers.xml in res/values/:

     <integer
            name="center"
            >17</integer>
    

    and in your xml, do:

    android:gravity="@integer/center"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
My layout have ImageView(iv) and TextView(tv). I want to let the tv right of
I have the following layout in my xml file: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <FrameLayout android:id=@+id/logoLayout
I have a listview and a button in my layout file. I want to
I have an appwidget layout with a textview and an imageview. Lint always tells
I have this layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=wrap_content android:layout_height=wrap_content > <TextView android:id=@+id/solution_title
I have an XML layout that defines a TextView box 50px x 320px who
I have a Linear Layout that has a Button and a TextView on it.
Typical search layout having RelativeLayout, TextView, EditText and Button I have a.9.png image having
I have the following XML: <LinearLayout android:id=@+id/linearLayout1 android:layout_width=fill_parent android:layout_height=wrap_content > <TextView android:id=@+id/tv1 android:layout_width=wrap_content android:layout_height=wrap_content

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.