使用API 17进行渲染时,Android按钮文本未居中

11
在布局的图形视图中,当我从下面图片中显示的按钮中选择API 15或更低版本时,圆圈中的按钮上的文本看起来很好。

enter image description here

当我选择API 17时,尽管xml代码相同,但文本仍然错位。更改按钮填充不起作用。

enter image description here

这只是Eclipse存在的问题吗?还是可能会在新版本的Android中出现这种错位文本?
有什么解决方法吗?
XML代码:
<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>

4个回答

10

android:gravity="center" 没有帮助

我重启了两次eclipse。奇怪的是,在第一次重启后它没有起作用,但在第二次重启后看起来很好。而且在设备上也工作正常。 对不起,我的问题可能是没耐心等待就发了出来。


3

不确定API17中按钮的默认样式是否改变了...

无论如何,添加 android:gravity="center" 应该可以解决这个问题。


2
我不知道我遇到了这个问题,尝试重新启动Eclipse并检查。

0

在你的代码中添加 android:gravity="center" 应该可以解决这个问题


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接