从左至右,从右至左滑动图像 [英] Slide image from left to right and right to left

查看:191
本文介绍了从左至右,从右至左滑动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,我想添加图片从左至右,从右到左像下面的图像,可以滑动的应用程序。内心的白玩形象应该是移动由左到右,反之亦然。

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.

下面是我的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;
    }
});

修改

我试图通过设置我的布局XML像下面来管理背景图片:

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.

任何想法和建议将应用preciated

Any idea and advice will be apppreciated

推荐答案

能不能请你这块$ C $的çJuned

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);
        }
    });
}}

这篇关于从左至右,从右至左滑动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆