Unknown On 2014년 6월 30일 월요일

버튼이 눌렸을때와 안 눌렸을때 각 버튼이미지를 res->xhdpi에 넣어주고
res폴더 안에 있는 drawable-hdpi  폴더안에 마우스 오른쪽 클릭하여
android-xml 파일을 눌러 selector 을선택한다. 
ex) button_click.xml

그리고 그 안에 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:state_pressed="true" android:drawable="@drawable/after_button" />
<!--   눌린 후 버튼이미지 파일명을 써준다.-->
 <!-- pressed -->  

 <item android:drawable="@drawable/before_button" /> 
<!--  눌리기 전 버튼이미지 파일명을 써준다..-->
 <!-- default -->
</selector>


저기에다가 눌렀을때 이미지(after_button)
          안눌렀을때 이미지(before_button)
위와 같이 해주고
activity_main으로 가서 
이미지버튼 눌림효과를 줄 xml 파일로 가서 이미지버튼 부분에 
android:background="@drawable/button_click"
이걸 추가해준다. 
button_click 은 아까 drawable 폴더 안에 만들어둔 xml 파일명이다.

 <ImageButton
        android:id="@+id/button_custom"
        android:layout_width="100sp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="143dp"
        android:background="@drawable/button_click" />

이렇게 하면 눌림효과가 만들어진다.


1.이미지 2개를 준비.
  (이미지들은 xhdpi 폴더에 넣는다)
2.hdpi 폴더에 xml 파일을 만든다.
 hdpi폴더 안에 xml에서 xhdpi의 들어간 이미지 2개 파일명을적는다(눌럿을때 효과, 안눌렀을때 효과)
3.layout 폴더에 xml 파일로가서 이미지버튼눌름효과를 줄 그곳에 hdpi의 xml 파일명을 적어주 면끝.




Leave a Reply

Subscribe to Posts | Subscribe to Comments

Powered by Blogger.