【发布时间】:2011-11-05 07:12:06
【问题描述】:
所以我开始考虑扩展 ToggleButton,以便除了在选择器中使用状态之外,我还想在它之上进行绘制。当我这样做时,我意识到高度和 layout_height 似乎存在问题,我可能遗漏了一些东西......
t按钮
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/on"/>
<item android:state_checked="false" android:drawable="@drawable/off"/>
</selector>
现在在布局 xml 中(当然是片段)
<ToggleButton android:id="@+id/mytoggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tbutton"
android:textOn=""
android:textOff=""
android:layout_weight="0"
android:focusableInTouchMode="false"
android:focusable="false"
android:layout_marginRight="@dimen/PADDING"/>
<edu.ninjacore.components.codeToggle android:id="@+id/mytoggle2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="0"/>
在我的构造函数中创建codeToggle(没什么花哨的)
public codeToggle(Context context)
{
super(context);
setBackgroundDrawable(getResources().getDrawable(R.drawable.tbutton));
}
您会发现 codeToggle 的高度与 ToggleButton 的高度不同......就像顶部和底部有更多的填充一样。
为什么会这样,你会如何纠正它?
谢谢, 凯莉
【问题讨论】:
标签: android xml class height togglebutton