Неустойчивая анимация с Android-вещами - PullRequest
0 голосов
/ 13 октября 2018

Я работал над программным обеспечением Smart Mirror на базе Android Things.На данный момент это просто своего рода макет.После добавления Translate Animations к виджетам они выглядят очень медленными и прерывистыми в портретном режиме :

Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context=".MainActivity">

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/time"
    android:layout_below="@+id/time"
    android:text="Saturday, 13 October"
    android:textColor="@android:color/white"
    android:textSize="25sp" />

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="44dp"
    android:layout_marginTop="62dp"
    android:text="09:41"
    android:textColor="@android:color/white"
    android:textSize="70sp" />

<ImageView
    android:id="@+id/weatherTypeImg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignStart="@+id/date"
    android:layout_marginTop="233dp"
    android:src="@drawable/ic_wb_sunny_black_24dp" />

<TextView
    android:id="@+id/temp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/date"
    android:layout_below="@+id/weatherTypeImg"
    android:text="28°"
    android:textColor="@android:color/white"
    android:textSize="20sp" />

<TextView
    android:id="@+id/weatherType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/date"
    android:layout_below="@+id/temp"
    android:fontFamily="sans-serif-condensed"
    android:text="Sunny"
    android:textColor="@android:color/white"
    android:textSize="14sp" />

</RelativeLayout>'

MainActivity.java:

package com.ladiesman6969.SmartMirror;


import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;


public class MainActivity extends Activity {

TextView date;
TextView time;
TextView temp;
ImageView weatherTypeImg;
TextView weatherType;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getActionBar().hide();

    date = findViewById(R.id.date);
    time = findViewById(R.id.time);
    temp = findViewById(R.id.temp);
    weatherTypeImg = findViewById(R.id.weatherTypeImg);
    weatherType = findViewById(R.id.weatherType);


    TranslateAnimation timeStartAnimation = new TranslateAnimation(-100,0,0,0);
    timeStartAnimation.setInterpolator(new LinearInterpolator());
    timeStartAnimation.setStartOffset(500);
    timeStartAnimation.setDuration(500);

    TranslateAnimation dateStartAnimation = new TranslateAnimation(-100,0,0,0);
    dateStartAnimation.setInterpolator(new LinearInterpolator());
    dateStartAnimation.setStartOffset(600);
    dateStartAnimation.setDuration(500);

    TranslateAnimation weatherImageStartAnimation = new TranslateAnimation(-250,0,0,0);
    weatherImageStartAnimation.setInterpolator(new LinearInterpolator());
    weatherImageStartAnimation.setStartOffset(700);
    weatherImageStartAnimation.setDuration(500);

    TranslateAnimation temperatureStartAnimation = new TranslateAnimation(-250,0,0,0);
    temperatureStartAnimation.setInterpolator(new LinearInterpolator());
    temperatureStartAnimation.setStartOffset(800);
    temperatureStartAnimation.setDuration(500);

    TranslateAnimation weatherTypeStartAnimation = new TranslateAnimation(-250,0,0,0);
    weatherTypeStartAnimation.setInterpolator(new LinearInterpolator());
    weatherTypeStartAnimation.setStartOffset(900);
    weatherTypeStartAnimation.setDuration(500);

    date.startAnimation(dateStartAnimation);
    time.startAnimation(timeStartAnimation);
    weatherTypeImg.startAnimation(weatherImageStartAnimation);
    temp.setAnimation(temperatureStartAnimation);
    weatherType.setAnimation(weatherTypeStartAnimation);
  }
}

Когда я запускаю этот код в эмуляторе Android, добавляя его, он работает абсолютно гладко.

Когда я запускаю этот код на моей Raspberry Pi 3 Model B с последней версией Android Things Build(1.0.5), он хорошо работает в ландшафтном режиме.

Что-то удивительное в том, что когда я запускаю этот код с ориентацией как портрет, анимация очень дрянная .

Вот небольшое видео для справки.

Заранее спасибо:)

...