按钮问题下的Android中心文字

时间:2013-02-22 17:06:53

标签: android android-layout android-button android-textattributes

我正在尝试将文本置于我的按钮下面,这是一个图像。但是,当文本大小为5sp时,它仅位于图像下方。除此之外的任何东西,它向左移动。

我认为这与图像有关?

我正在实施dashboard layout

我的代码与链接相同,但我使用的是64x64图像。

Style.xml

`<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="DashboardButton">
        <item name="android:layout_gravity">center_vertical</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:drawablePadding">2dp</item>
        <item name="android:textSize">14sp</item> <!-- I have to make this 5sp to center-->
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#ff0000</item>
        <item name="android:background">@null</item>
    </style>
</resources>`

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >  



<com.test.layout.DashboardLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button android:id="@+id/dashboard_button_add"
        style="@style/DashboardButton"
        android:text="@string/activity_add"
        android:drawableTop="@drawable/dashboard_button_add" />

    <Button android:id="@+id/dashboard_button_viewall"
        style="@style/DashboardButton"
        android:text="@string/activity_viewall"
        android:drawableTop="@drawable/dashboard_button_add" />

    <Button android:id="@+id/dashboard_button_manage"
        style="@style/DashboardButton"
        android:text="@string/activity_manage"
        android:drawableTop="@drawable/dashboard_button_add" />

    <Button android:id="@+id/dashboard_button_personalbests"
        style="@style/DashboardButton"
        android:text="@string/activity_personalbests"
        android:drawableTop="@drawable/dashboard_button_add" />    

</com.test.layout.DashboardLayout>

dashboard_button_add.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/dashboard_add_button_selected"
        android:state_focused="true"
        android:state_pressed="true" />
    <item android:drawable="@drawable/dashboard_add_button_selected"
        android:state_focused="false"
        android:state_pressed="true" />
    <item android:drawable="@drawable/dashboard_add_button_selected" android:state_focused="true" />
    <item android:drawable="@drawable/dashboard_add_button_default"
        android:state_focused="false"
        android:state_pressed="false" />
</selector>

dashboard_add_button_default和dashboard_add_button_selected为64x64 png。

如果我正确对齐文本它停止它不会超过图像。

0 个答案:

没有答案