[英]Toggle button image is not centered
That's how it looks: http://i.imgur.com/navAYXk.jpg 看起来就是这样: http : //i.imgur.com/navAYXk.jpg
And here's the code responsible for the layout: (togglebutton in question is the last one) 这是负责布局的代码:(有问题的切换按钮是最后一个)
<?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>
And here is the file toggle_check.xml: 这是文件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>
I have no idea why that togglebutton image is not centered, can anybody help me with that? 我不知道为什么切换按钮图像没有居中,有人可以帮我吗?
Your layout seems ok to me. 您的布局对我来说似乎还可以。 I'd try replacing the
ToggleButton
for another ImageButton
, just to make sure android does not add some padding automatically as it does with CheckBoxes
. 我会尝试将
ToggleButton
替换为另一个ImageButton
,以确保android不会像CheckBoxes
那样自动添加一些填充。 Also, double check that neither player_shuffle_on
nor player_shuffle_off
pngs have been accidentally saved with a transparent padding. 另外,请仔细检查
player_shuffle_on
和player_shuffle_off
png是否都没有用透明填充意外保存。
By the way, there's no need for two LinearLayouts
, you can have just one horizontal LinearLayout
as your root view. 顺便说一句,不需要两个
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.