我正在开发一个应用程序,想要添加一个可以从左到右、从右到左滑动的图像,就像下面的图片一样。那个内部的白色播放图标应该从左向右移动,反之亦然。
我已经做了一些工作,能够将单个图像从左到右移动,反之亦然,但我希望设置背景图像,就像上面圆形黑色背景一样。
以下是我的代码:
我已经做了一些工作,能够将单个图像从左到右移动,反之亦然,但我希望设置背景图像,就像上面圆形黑色背景一样。
以下是我的代码:
imageView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
int x = (int) event.getRawX();
mParams.leftMargin = x - 50;
imageView.setLayoutParams(mParams);
break;
default:
break;
}
return true;
}
});
编辑
我尝试通过以下设置我的布局xml文件以管理背景图片:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="49dp"
android:background="@drawable/set_user_profile_back"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/hello_world"
android:src="@drawable/next" />
</RelativeLayout>
</RelativeLayout>
但现在我面临的问题是图片大小,图片在右侧减小了,如何解决,并如何固定图像移动的起点和终点。
如果有任何想法和建议,将不胜感激。