其他分享
首页 > 其他分享> > Foursquare Android顶级横幅动画

Foursquare Android顶级横幅动画

作者:互联网

我们如何在android应用程序中添加缩放图像背景?它在早期版本的android twitter登陆页面(不是主页)中可用,当前在foursquare中,顶部横幅背景具有相同的动画.
您可以通过以下链接查看动画的视频.
Animation video on youtube

我在网上搜索,但找不到任何解决方案.可能是我的关键字有误.
任何指导方针将不胜感激.

解决方法:

我发现有黑客可以这样做.但是我不确定这是否是执行此操作的最佳方法.
在Android API演示中,com.example.android.apis.graphics包中有一个名为AnimateDrawables的类.使用那个理论,我完成了这项工作.

添加一个Framelayout作为基本布局,您可以在其他小部件之间添加动画视图.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/FrameLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <com.cit.testmovingbg.MovingBGView
        android:id="@+id/movingBGView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:text="@string/app_name"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF"
        android:textSize="35sp" />

</FrameLayout>

MovingBGView类是视图类的子类,如下所示

public class MovingBGView extends View {

    private AnimateDrawable mDrawable;

    public MovingBGView(Context context) {
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);

        Drawable dr = context.getResources().getDrawable(R.drawable.colombo);
        dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());

        Animation an = new TranslateAnimation(0, 100, 0, 200);
        an.setDuration(2000);
        an.setRepeatCount(-1);
        an.initialize(10, 10, 10, 10);

        mDrawable = new AnimateDrawable(dr, an);
        an.startNow();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);

        mDrawable.draw(canvas);
        invalidate();
    }   
}

标签:foursquare,twitter,android-animation,android-image,android
来源: https://codeday.me/bug/20191030/1964408.html