繁体   English   中英

切换按钮图像未居中

[英]Toggle button image is not centered

看起来就是这样: http : //i.imgur.com/navAYXk.jpg

这是负责布局的代码:(有问题的切换按钮是最后一个)

<?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:background="@drawable/border" >

            <ImageButton
                android:id="@+id/playpause"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:background="@null"
                android:src="@drawable/player_play"
                android:text="play/pause" />

            <ImageButton
                android:id="@+id/prev"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:background="@null"
                android:src="@drawable/player_prev"
                android:text="prev" />

            <ImageButton
                android:id="@+id/next"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:background="@null"
                android:src="@drawable/player_next"
                android:text="next" />

            <ToggleButton
                android:id="@+id/shuffleButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:background="@null"
                android:button="@drawable/toggle_check"
                android:layout_gravity="center"
                android:textOff=""
                android:textOn="" />

        </LinearLayout>

</LinearLayout>

这是文件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 ,以确保android不会像CheckBoxes那样自动添加一些填充。 另外,请仔细检查player_shuffle_onplayer_shuffle_off png是否都没有用透明填充意外保存。

顺便说一句,不需要两个LinearLayouts ,您只需一个水平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
                ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM