
我看到了可以用 XML表示的TransitionDrawable对象.有没有办法将它连接到我的选择器?
下面是在屏幕左下角的屏幕上创建图像按钮的XML布局代码.它目前从一个图像到另一个图像突然忽略了转换XML.
selector_button.xml
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:state_pressed="true" androID:drawable="@drawable/Transition_normal_to_pressed" /> <!-- pressed --> <item androID:state_focused="true" androID:drawable="@drawable/Transition_pressed_to_normal" /> <!-- focused --> <item androID:drawable="@drawable/menu_normal" /> <!-- default --></selector>
Transition_normal_to_pressed.xml
<?xml version="1.0" enCoding="utf-8"?><Transition xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:drawable="@drawable/menu_pressed" /> <item androID:drawable="@drawable/menu_normal" /></Transition>
activity.xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <Imagebutton androID:ID="@+ID/btnMenu" androID:background="@androID:color/transparent" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:src="@drawable/selector_button" androID:layout_alignParentleft="true" androID:layout_alignParentBottom="true" /></relativeLayout>解决方法 您需要删除选择器并直接使用过渡作为Imagebuttons drawable.动画本身必须在代码中应用
Imagebutton button = (Imagebutton) findVIEwByID(R.ID.button);TransitionDrawable drawable = (TransitionDrawable) button.getDrawable();drawable.startTransition(500);
drawable.reverseTransition(500)将从当前状态转换为转换.
有关进一步说明,请参阅Transition Drawable以及TransitionDrawable.HTML#reverseTransition(int).
总结以上是内存溢出为你收集整理的ImageButton在Android中使用Transitions全部内容,希望文章能够帮你解决ImageButton在Android中使用Transitions所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)