Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Создать приложение для ОС Android в среде Android Studio

Автор:   •  Апрель 27, 2022  •  Лабораторная работа  •  1,145 Слов (5 Страниц)  •  179 Просмотры

Страница 1 из 5

Лабораторная работа №3

по дисциплине «Мобильные и встраиваемые операционные системы»

Задача:

Создать приложение для ОС Android в среде Android Studio – Анимация.

На экране расположены четыре кнопки (Frame animation, Transform animation, Cancel animation и Move animation). При нажатии на первую кнопку воспроизводится покадровая анимация (вращение), при нажатии на вторую – анимация преобразований (сжатие), при нажатии на третью анимация прекращается и при нажатии на четвертую анимация меняется прозрачность и размер изображения.

Код MainActivity.java (app/java/com.example.lab3/)

package com.example.lab3;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

   
private ImageView animationView;

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

       
animationView = (ImageView) findViewById(R.id.animationView);
   
}

   
public void frameAnimationStart(View view) {
       
animationView.setBackgroundResource(R.drawable.frame_anim);
       
AnimationDrawable animation = (AnimationDrawable) animationView.getBackground();
       
animation.start();
   
}

   
public void cancelAnimation(View view) {
       
animationView.setBackgroundColor(Color.WHITE);
   
}

   
public void transformAnimationStart(View view) {
       
animationView.setBackgroundResource(R.drawable.ic_launcher);
       
Animation transformAnimation = AnimationUtils.loadAnimation(this, R.anim.transform_anim);
       
animationView.startAnimation(transformAnimation);
   
}

   
public void moveButtonClick(View view) {
       
animationView.setBackgroundResource(R.drawable.ic_launcher);
       
Animation moveAnimation = AnimationUtils.loadAnimation(this, R.anim.move_anim);
       
animationView.startAnimation(moveAnimation);
   
}
}

Код activity_main.xml (app/res/layout/)

<?xml version="1.0" encoding="utf-8"?>
<
androidx.constraintlayout.widget.ConstraintLayout 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"
   
tools:context=".MainActivity">


   <
ImageView
       
android:id="@+id/animationView"
       
android:layout_width="289dp"
       
android:layout_height="259dp"
       
android:layout_weight="1"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintStart_toStartOf="parent"
       
app:layout_constraintTop_toTopOf="parent"
       
app:layout_constraintVertical_bias="0.942" />

   <
Button
       
android:id="@+id/moveButton"
       
android:layout_width="222dp"
       
android:layout_height="50dp"
       
android:onClick="moveButtonClick"
       
android:text="MOVE ANIMATION"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintHorizontal_bias="0.518"
       
app:layout_constraintStart_toStartOf="parent"
       
app:layout_constraintTop_toBottomOf="@+id/cancelAnimation"
       
app:layout_constraintVertical_bias="0.012" />

   <
Button
       
android:id="@+id/transformAnimationStart"
       
android:layout_width="222dp"
       
android:layout_height="50dp"
       
android:layout_marginBottom="4dp"
       
android:onClick="transformAnimationStart"
       
android:text="Transform animation"
       
app:layout_constraintBottom_toTopOf="@+id/cancelAnimation"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintHorizontal_bias="0.518"
       
app:layout_constraintStart_toStartOf="parent" />

   <
Button
       
android:id="@+id/frameAnimationStart"
       
android:layout_width="222dp"
       
android:layout_height="50dp"
       
android:layout_marginTop="32dp"
       
android:onClick="frameAnimationStart"
       
android:text="Frame animation"
       
app:layout_constraintBottom_toTopOf="@+id/transformAnimationStart"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintHorizontal_bias="0.518"
       
app:layout_constraintStart_toStartOf="parent"
       
app:layout_constraintTop_toTopOf="parent"
       
app:layout_constraintVertical_bias="0.845" />
   <
Button
       
android:id="@+id/cancelAnimation"
       
android:layout_width="222dp"
       
android:layout_height="50dp"
       
android:layout_marginBottom="448dp"
       
android:onClick="cancelAnimation"
       
android:text="Cancel animation"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintHorizontal_bias="0.518"
       
app:layout_constraintStart_toStartOf="parent" />

</
androidx.constraintlayout.widget.ConstraintLayout>

...

Скачать:   txt (8.6 Kb)   pdf (360.3 Kb)   docx (246.6 Kb)  
Продолжить читать еще 4 страниц(ы) »
Доступно только на Essays.club