0

I have the following layout XML file:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_gravity="center"> // The layout_gravity doesn't seem to affect // the button Views // (I guess this is the wrong way to do it) <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Genre1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Genre2" /> </LinearLayout> 

How do I make a single general attribute configuration e.g. android:layout_gravity="center" for all my Button Views?

2
  • can u show how you want to display in xml?? Commented Jul 12, 2012 at 12:48
  • pls describe how ur xml should look like?? Commented Jul 12, 2012 at 13:00

3 Answers 3

2

You could wrap common attributes for a certain View under a style.

Create a styles.xml file in your values folder, and just declare the styles:

<style name="list_item_title"> <item name="android:textStyle">bold</item> <item name="android:textColor">@android:color/black</item> <item name="android:textSize">18sp</item> <item name="android:padding">0dp</item> </style> 

Then, on your TextView (or Button, or whatever View...):

<TextView android:id="@+id/tv1" style="@style/list_item_title" /> 
Sign up to request clarification or add additional context in comments.

Comments

0

Write below line

android:gravity="center" 

instead of

android:layout_gravity="center" 

it will solve your problem.

Comments

0

have you tried android:gravity="center" instead of android:layout_gravity="center"

or you can try android:layout_gravity="center" in your buttons xml

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.