Slide image from left to right and right to left

android

Solution

Can you please try this piece of code Juned

public class MainActivity extends Activity {

Button b1;
ImageView logo;
float width;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b1 = (Button) findViewById(R.id.button1);
    logo = (ImageView) findViewById(R.id.logo);

    Display display = getWindowManager().getDefaultDisplay();
    width = display.getWidth();
    final Animation posX = new TranslateAnimation(0, width - 50, 0, 0);
    posX.setDuration(1000);
    posX.setFillAfter(true);

    b1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            logo.startAnimation(posX);
            logo.setVisibility(View.VISIBLE);
        }
    });
}}

Problem

I am developing an application in which I want to add image which can slide from left to right and from right to left like below image. That inner white play image should be move from left to right and Vice Versa. What I have did so far is, I am able to move single image from left to right and vice versa but I want set background image as well like above rounded shaped black background. Here is my code: ``` 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; } }); ``` EDIT I tried to manage background image by setting my layout xml like below: ``` <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> ``` But now I am facing problem with image size, image size is decreased in right how to solve this and how to fix start and end point for image movement. Any idea and advice will be apppreciated

Original source

Related problems