ImageButton点击后拖出
ImageButton drag out after click
我有一个 ImageButton
(保存),可以用手指拖入。
我希望点击后自动拖出(现在我必须点击屏幕,才能拖出 ImgBtn)
这就是我在 xml 中声明按钮的方式:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
<!-- this is my image button -->
<ImageButton
android:id="@+id/imageButton"
android:layout_gravity="bottom|end"
android:layout_width="130dip"
android:layout_height="65dip"
android:scaleType="centerCrop"
android:src="@drawable/save" />
</android.support.v4.widget.DrawerLayout>
有什么建议吗?
我看到唯一的方法是使用动画和 OnClick 以编程方式启动动画 "android:fillAfter" 为真。
如果我理解你是对的,"drag out" 意思是滑出屏幕。
slideOut.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%" />
</set>
布局中
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="SlideOut" />
在代码中
function SlideOut() {
findViewById(R.id.imageButton).startAnimation(AnimationUtils.loadAnimation(this, R.anim.slideOut));
}
我有一个 ImageButton
(保存),可以用手指拖入。
我希望点击后自动拖出(现在我必须点击屏幕,才能拖出 ImgBtn)
这就是我在 xml 中声明按钮的方式:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
<!-- this is my image button -->
<ImageButton
android:id="@+id/imageButton"
android:layout_gravity="bottom|end"
android:layout_width="130dip"
android:layout_height="65dip"
android:scaleType="centerCrop"
android:src="@drawable/save" />
</android.support.v4.widget.DrawerLayout>
有什么建议吗?
我看到唯一的方法是使用动画和 OnClick 以编程方式启动动画 "android:fillAfter" 为真。
如果我理解你是对的,"drag out" 意思是滑出屏幕。
slideOut.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%" />
</set>
布局中
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="SlideOut" />
在代码中
function SlideOut() {
findViewById(R.id.imageButton).startAnimation(AnimationUtils.loadAnimation(this, R.anim.slideOut));
}