Android的自动滚动的ImageViewAndroid、ImageView

2023-09-05 07:59:56 作者:这个网名不错

在我的活动我都只是一个ImageView的。在这里面,SRC是图片比屏幕大很多。我要的照片,直到达到照片的右边距slooooowly滚动由左到右,然后开始向后滚动向左,直到左利润率达到。然后从头再来。 我需要它发生在一个单独的线程所以手机会不会结冰而发生这种情况。

In my activity I have just an ImageView. In it, the src is a picture that is a lot bigger than the screen. I want the picture to scroll slooooowly from left to right until it reaches the right margin of the photo, then start scrolling back towards left until left margin reached. Then start all over again. I need it to happen in a separate thread so the phone would not freeze while this happens.

我怎样才能做到这一点? 是否有一个小部件,它在默认情况下做到这一点?

How can I achieve this? Is there a widget that does this by default?

修订code //布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylinear"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"
        android:src="@drawable/rainforest" />

</RelativeLayout>

//和活动

// and Activity

public class MainActivity extends Activity {

    Animation           _translateAnimation;
    RelativeLayout        _relativeLoading = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        _translateAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, -100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
        _translateAnimation.setDuration(5000);
        _translateAnimation.setRepeatCount(-1);
        _translateAnimation.setRepeatMode(Animation.REVERSE); // REVERSE
        _translateAnimation.setInterpolator(new LinearInterpolator());
        _relativeLoading = (RelativeLayout) findViewById(R.id.mylinear);
        _relativeLoading.startAnimation(_translateAnimation);
    }

但它熄灭的图片。 我的意思是,滚动变为从左至右,推的图片的左侧和示出白色背景波纹管ImageView的

But it goes off the picture. I mean, the scroll goes from left to right, "pushing" the picture to the left and showing the white background bellow the ImageView.

此外,这应该是一个线程或里面的东西?我需要能够退出这场滚动运动在某种程度上,不使用后退按钮。我想在ImageView的顶部的按钮(按钮应保持不动)和它的onClick应该开始另一个意图

Also, should this be inside a thread or something? I need to be able to exit this "scrolling" activity somehow, without using the Back button. I want a button on top of the ImageView (the button should stay still) and onClick it should start another Intent

这似乎是ImageView的内部照片被裁剪以适合屏幕内。我怎样才能解决这个?

It seems like the picture inside the ImageView is cropped to fit inside the screen. How can I overcome this?

推荐答案

例:

private Animation           _translateAnimation;
private ImageView       _image;

_image = (ImageView)findViewById(R.id.yourimage);

_translateAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
_translateAnimation.setDuration(10000);
_translateAnimation.setRepeatCount(-1);
_translateAnimation.setRepeatMode(Animation.REVERSE);
_translateAnimation.setInterpolator(new LinearInterpolator());
_image.setAnimation(_translateAnimation);

这将使_linearLoading慢慢翻译权,左,右和左...

ImageView的属性android scaleType作用

This will make _linearLoading translate slowly right and left and right and left...

更多时间=更慢

TranslateAnimation.ABSOLUTE =与图像的位置的工作 TranslateAnimation.RELATIVE_TO_PARENT =工作与父布局 ......

TranslateAnimation.ABSOLUTE = Work with the position of the image TranslateAnimation.RELATIVE_TO_PARENT = Work with the parent layout ...

该方法TranslateAnimation(启动x,结束X,启动Y,结束Y)

The method TranslateAnimation(start x, end x, start y, end y)

与玩