일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- v8 engine xcode build
- Status Bar
- Push
- 공인인증서 정보
- 인증서 정보 뽑아내기
- FlexiblePageView
- embedd
- apache
- appbarlayout
- Objective C
- apns
- V8 Engine
- Android
- ios framework
- ios
- android log dump
- sha1 convert hashkey
- JavaScript Engine
- Android NDK시스템
- 안드로이드
- IMAGE
- PageControl
- SO 파일
- apk 다운사이징
- IOS10
- Magnify Anim
- java
- so file
- Google V8 Engine
- 공인인증서 만료일
Archives
- Today
- Total
caTea 블로그
android frame animation class 본문
반응형
/**
* Created by achee7059 on 2017. 2. 22..
*/
public class AnimImageView extends ImageView{
private Context mContext;
private AnimationDrawable mAnimationDrawable;
public AnimImageView(Context context) {
super(context);
mContext= context;
}
public AnimImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
mContext= context;
}
public AnimImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext= context;
}
public boolean initAnimResource(ArrayList<AnimConfig> animImageIdList, boolean isOneShot) {
boolean result = false;
if(animImageIdList != null){
try {
BitmapDrawable bitmapDrawable = null;
mAnimationDrawable = new AnimationDrawable();
mAnimationDrawable.setOneShot(isOneShot); // 반복실행하겠다
for(AnimConfig config : animImageIdList){
bitmapDrawable = (BitmapDrawable)ContextCompat.getDrawable(mContext, config.getImageId());
mAnimationDrawable.addFrame(bitmapDrawable, config.getDuration());
}
this.setBackground(mAnimationDrawable);
result = true;
}catch (Exception e){
result = false;
}
}
return result;
}
public void start(){
if(mAnimationDrawable != null){
mAnimationDrawable.start();
}
}
public void stop(){
if(mAnimationDrawable != null){
mAnimationDrawable.stop();
}
}
public boolean isRunning(){
boolean isRun = false;
if(mAnimationDrawable != null){
isRun = mAnimationDrawable.isRunning();
}
return isRun;
}
}
====================================================================
public class AnimConfig implements Serializable {
/**
* 이미지 리소스 아이디 (Ex. R.drawable.example)
*/
private int imageId;
/**
* 얼마동안 움직일지 시간
*/
private int duration;
public AnimConfig(){}
public AnimConfig(int imageId, int duration){
this.imageId = imageId;
this.duration = duration;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
}
===================================================
사용방법
mAnimImageView = (AnimImageView) view.findViewById(R.id.recommend_anim_view);
ArrayList<AnimConfig> configList = new ArrayList<AnimConfig>();
AnimConfig config = null;
for (int i = 1; i < 10; i++) {
int resID = getResources().getIdentifier("naruto0"+i, "drawable", "com.ubist.tourtainment.flag");
config = new AnimConfig();
config.setImageId(resID);
config.setDuration(200);
configList.add(config);
}
boolean isSuccess = mAnimImageView.initAnimResource(configList, false);
Log.d(TAG, "anim is Success : "+isSuccess);
mAnimImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mAnimImageView.isRunning()){
mAnimImageView.stop();
mAnimImageView.start();
} else {
mAnimImageView.start();
}
}
});
728x90
'android' 카테고리의 다른 글
AppBarLayout 부드럽게 스크롤 (0) | 2017.04.14 |
---|---|
Magnify Anim View Pager (0) | 2017.03.13 |
android permission activity (0) | 2017.02.22 |
vertical view pager (0) | 2016.07.01 |
이미지 라운드 처리 클래스 (0) | 2016.06.28 |