質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

1回答

1387閲覧

複数の画像をGIFのようにアニメーションができない

RYOHEI1009

総合スコア45

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2017/05/28 10:22

編集2017/05/28 13:25

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:id="@+id/linearLayout1" 8 android:layout_centerHorizontal="true" 9 android:gravity="center_vertical" 10 tools:context="com.example.ryo.test6.MainActivity"> 11 12 13 <TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="NFCをかざしてください" 17 app:layout_constraintBottom_toBottomOf="parent" 18 app:layout_constraintLeft_toLeftOf="parent" 19 app:layout_constraintRight_toRightOf="parent" 20 app:layout_constraintTop_toTopOf="parent" 21 app:layout_constraintVertical_bias="0.109" /> 22 23 <ImageView 24 android:id="@+id/imageView3" 25 android:layout_width="236dp" 26 android:layout_height="195dp" 27 app:srcCompat="@drawable/nfc_anim" 28 /> 29 30 31</android.support.constraint.ConstraintLayout>java 32 33

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context="com.example.ryo.test6.BaseActivity"> 8 9</android.support.constraint.ConstraintLayout> 10```java 11package com.example.ryo.test6; 12 13import android.content.Intent; 14import android.nfc.NfcAdapter; 15import android.os.Build; 16import android.provider.Settings; 17import android.support.v7.app.AppCompatActivity; 18import android.os.Bundle; 19import android.widget.Toast; 20public class BaseActivity extends AppCompatActivity { 21protected NfcAdapter mNfcAdapter; 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.activity_base); 26 //NFCを扱うためのインスタンスを取得 27 mNfcAdapter=NfcAdapter.getDefaultAdapter(this); 28 //NFCが搭載されているかチェックする 29 if(mNfcAdapter!=null){ 30 //NFC機能が有効になっているかチェックする 31 if(!mNfcAdapter.isEnabled()){ 32 //NFC機能が無効の場合はユーザーへ通知 33 Toast.makeText(getApplicationContext(),"error_nfc_disable", Toast.LENGTH_SHORT).show(); 34 } 35 else { 36 Toast.makeText(getApplicationContext(), "error_nfc_nosupport", Toast.LENGTH_SHORT).show(); 37 } 38 } 39 if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){ 40 startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); 41 } 42 } 43 44} 45

java

1package com.example.ryo.test6; 2 3import android.app.PendingIntent; 4import android.content.Context; 5import android.content.Intent; 6import android.graphics.drawable.AnimationDrawable; 7import android.nfc.NfcAdapter; 8import android.os.Vibrator; 9import android.support.v7.app.AppCompatActivity; 10import android.os.Bundle; 11import android.widget.ImageView; 12import android.widget.Toast; 13 14import java.util.Arrays; 15public class MainActivity extends AppCompatActivity { 16 17 private NfcAdapter mNfcAdapter; 18 19 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 setContentView(R.layout.activity_main); 24 mNfcAdapter = NfcAdapter.getDefaultAdapter(this); 25 } 26 /* 27 * onWindowFocusChanged()はフォーカスが変わった時に呼ばれる 28 */ 29 @Override 30 public void onWindowFocusChanged(boolean hasFocus) { 31 super.onWindowFocusChanged(hasFocus); 32 33 ImageView img = (ImageView) findViewById(R.id.imageView3); 34 35 // AnimationDrawableのXMLリソースを指定 36 img.setBackgroundResource(R.drawable.nfc_anim); 37 38 // AnimationDrawableを取得 39 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); 40 41 // Animationの開始 42 frameAnimation.start(); 43 } 44 45 46 47 48 49 @Override 50 protected void onResume() { 51 super.onResume(); 52 53 //NFCカードがかざされた際に、現在のActivityで優先的に受け取る設定を行います。 54 Intent intent = new Intent(this, this.getClass()); 55 intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 56 PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 57 mNfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null); 58 } 59 @Override 60 protected void onPause() { 61 super.onPause(); 62 //Activityがバックグランドに回った際は優先的に受け取る情報を停止します 63 mNfcAdapter.disableForegroundDispatch(this); 64 } 65 //NFC-UIDを、文字列に変換して表示します。 66 @Override 67 protected void onNewIntent(Intent intent){ 68 //かざしデータを受け取ったときにバイブを鳴らす。 69 ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(100); 70 super.onNewIntent(intent); 71 //NFC-UIDを取得します。 72 byte[] uid=intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); 73 //NFC-UIDを文字列に変換して表示します。 74 Toast.makeText(this, Arrays.toString(uid),Toast.LENGTH_SHORT).show(); 75 } 76 77}

XML

1<?xml version="1.0" encoding="utf-8"?> 2<selector xmlns:android="http://schemas.android.com/apk/res/android"> 3 4 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 5 android:oneshot="false"> 6 7 <!-- duration:アニメーションの間隔(ms単位の整数値) --> 8 <item 9 android:drawable="@drawable/nfcreader1" 10 android:duration="150"/> 11 <item 12 android:drawable="@drawable/nfcreader2" 13 android:duration="150"/> 14 <item 15 android:drawable="@drawable/nfcreader3" 16 android:duration="150"/> 17 <item 18 android:drawable="@drawable/nfcreader4" 19 android:duration="150"/> 20 <item 21 android:drawable="@drawable/nfcreader5" 22 android:duration="500"/> 23 24 </animation-list> 25 26</selector>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

AnimationDrawableにはAnimationDrawableをxmlで定義するときはanimation-listタグを1つとその子要素としてitemタグを使えと書いてあります。
つまり、selectorの子要素として定義はできないと思います。

投稿2017/05/28 16:56

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問