【问题标题】:How to slide a bit map drawable across the screen如何在屏幕上滑动可绘制的位图
【发布时间】:2015-10-17 07:11:33
【问题描述】:

我将首先说明我想要实现的目标。我有一张想在屏幕上滑动的图像。

问题是图像会自动调整以适应屏幕的纵横比。

我以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); 

动画没问题。就像我说的,问题是图像会自动调整以适应屏幕的纵横比。

【问题讨论】:

标签: android


【解决方案1】:

纵横比的问题是我没有将图像的宽度和高度设置为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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多