【问题标题】:Foursquare android top banner animationFoursquare android 顶部横幅动画
【发布时间】:2014-01-12 13:03:10
【问题描述】:

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

我在网上搜索但找不到任何解决方案。可能是我的关键字错误。 任何指南都将受到高度赞赏。

【问题讨论】:

    标签: android twitter android-animation foursquare android-image


    【解决方案1】:

    我发现了一个 hack 来做这件事。但我不确定这是否是最好的方法。 在 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();
        }   
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      相关资源
      最近更新 更多