Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Button text not centered when using API 17 for rendering

In the graphical view of layout, when I choose API 15 or lower from the button shown in the image below, the text in the encircled buttons looks fine.

enter image description here

When I choose API 17, the text is displaced even though the xml code is same. Changing the button padding does not help.

enter image description here

Is this just a problem with Eclipse or is it possible that new versions of android may see this displaced text?

What's the workaround to fix this?

XML code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_margin="3dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:src="@drawable/label" />
</LinearLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/linearLayout1"
    android:layout_below="@+id/linearLayout1"
    android:layout_marginTop="20dp"
    android:text="@string/about_title"
    android:textSize="20sp" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignRight="@+id/linearLayout1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="5dp"
    android:text="@string/temp" />

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignRight="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="20dp"
    android:baselineAligned="false" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/news" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/tournaments" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/results" />
</LinearLayout>

like image 305
Kartik Avatar asked Mar 23 '13 12:03

Kartik


2 Answers

android:gravity="center" did not help

I restarted eclipse twice. Strangely it did not help in the first restart but it looked fine after the second one. Also, its working fine on device. Apologies for the question, I must have waited before posting the question.

like image 126
Kartik Avatar answered Oct 07 '22 15:10

Kartik


Not sure if the default style for Buttons changed in API17... possibly...

Anyway, adding android:gravity="center" should be fixing this for you.

like image 33
Goddchen Avatar answered Oct 07 '22 15:10

Goddchen