2015-10-16 146 views
0

我将首先阐述我想达到的目标。我有一张想要在屏幕上滑动的图像。如何滑动在屏幕上绘制的位图

enter image description here

的问题是,图像被自动地调整以适应屏幕的宽高比。

我开始与ImageView

<ImageView 
    android:id="@+id/slidingImage" 
    android:src="@drawable/gazelleRunning" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

然后,我设置的ImageView

ImageView gazelleRunning = (ImageView) findViewById(R.id.gazelleRunning); 
Bitmap bitmap = BitmapFactory.decodeFile(URI_Object); 
Drawable drawable = new BitmapDrawable(getResources(), bitmap); 

gazelleRunning.setBackground(drawable); 

背景动画是没有问题的。就像我说的那样,问题是图像会自动调整以适应屏幕的高宽比。

+0

这些链接应该给你一些idea- http://stackoverflow.com/questions/18073588/androidhow-can-i-show-a-part-of- image –

+0

http://stackoverflow.com/questions/3466297/how-to-display-a-part-of-an-image –

+0

@RameshPrasad谢谢,但我想动画滚动视图实际上可以适应整个图像放入视图并基本滚动。 –

回答

0

与纵横比的问题是,我hand't图像的宽度和高度设定为wrap_content

在到目前为止作为在关注滑动,我解决了这个问题通过实施变换。

Animation animationSlideInLeft = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_from_right); 
gazelleRunning.startAnimation(animationSlideInLeft); 

动画文件

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" > 
    <translate 
     android:duration="5000" 
     android:fromXDelta="200%" 
     android:toXDelta="0%" 
     /> 
</set>