Android 切换按钮图像未居中

Android 切换按钮图像未居中,android,xml,layout,togglebutton,Android,Xml,Layout,Togglebutton,这就是它的样子: 下面是负责布局的代码:(最后一个是togglebutton) 下面是文件toggle_check.xml: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/player_shuffle_on"

这就是它的样子:

下面是负责布局的代码:(最后一个是togglebutton)


下面是文件toggle_check.xml:

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


我不知道为什么togglebutton图像没有居中,有人能帮我吗?

我觉得你的布局不错。我会尝试用另一个
ImageButton
替换
ToggleButton
,以确保android不会像使用
复选框那样自动添加一些填充。另外,请仔细检查
player\u shuffle\u on
player\u shuffle\u off
png是否被意外保存为透明填充

顺便说一下,不需要两个
LinearLayout
,您只需要一个水平
LinearLayout
作为根视图。

将重心添加到第二个线性布局:
Add Gravity-Center to your second Linear Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
            android:id="@+id/controls"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            *android:gravity="center"*
            android:background="@drawable/border" >

            <ImageButton
                ...
Add Gravity-Center to your second Linear Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
            android:id="@+id/controls"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            *android:gravity="center"*
            android:background="@drawable/border" >

            <ImageButton
                ...