ANDROID/CONCEPT
[Android] 08강. 버튼 이미지 애니메이션(Image Button)
너래쟁이
2018. 3. 27. 01:31
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.example.kbw.a8; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } | cs |
button1.xml
1 2 3 4 5 6 7 8 9 | <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/click" android:state_pressed="true"></item> <item android:drawable="@drawable/hover" android:state_hovered="true"></item> <item android:drawable="@drawable/normal" android:state_focused="true"></item> </selector> <!--1. 버튼이 press (click) 2. 마우스가 focus (hover) 3. normal--> | cs |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?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" tools:context="com.example.kbw.a8.MainActivity"> <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:background="@drawable/normal" app:srcCompat="@drawable/button1" tools:layout_editor_absoluteX="157dp" tools:layout_editor_absoluteY="68dp" /> </RelativeLayout> | cs |