'안드로이드'에 해당되는 글 5건

  1. 2020.05.13 Android Studio Firebase Crashlytics 설정
  2. 2020.05.11 반원(half circle) xml
  3. 2020.05.08 Android Animation scale
  4. 2020.05.08 Android Animation translate
  5. 2009.05.25 안드로이드 개발 준비

1.Gradle 설정

1)Project의 build.gradle 파일에 아래 처럼 추가한다.

//Firebase Crashlytics 주석이 달린 부분이다.

 

buildscript {
    ext.kotlin_version = '1.3.71'
    repositories {
        google()
        jcenter()
        maven{url 'https://maven.fabric.io/public'}//Firebase Crashlytics
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath 'io.fabric.tools:gradle:1.+'//Firebase Crashlytics
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{url 'https://maven.fabric.io/public'}//Firebase Crashlytics
    }
}

 

2)app 모듈의 build.gradle 파일에 다음과 같이 구성한다.

 

apply plugin: 'io.fabric'//Firebase Crashlytics


dependencies{
...
//Firebase Crashlytics
implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true;
    }
}

 

작성이 끝나면 Sync Now를 해준다.

 

2.소스코드

 

Main Activity에 작성할 내용이다.

 

1)아래 두 패키지를 임포트 한다.

 

import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

 

그리고 onCreate 메소드에서 초기화 코드를 추가한다.

 

Fabric.with(this, new Crashlytics());

 

3.옵션

추가로 플래그를 설정해 SDK를 사용설정하려면

strings.xml에서 다음 문자열을 추가한다.

<string name="com.crashlytics.useFirebaseAppId">true</string>

 

그리고 app 모듈 루트에 fabric.properties 파일을 생성하고 아래 내용을 입력한다.

USE_FIREBASE_APP_ID=true

 

 

Posted by Lumasca
,

반쪽짜리 원 모양이 필요할때가 있다.

drawable 에 xml 파일을 생성하고 아래를 참고해서 작성한다.

 

width, height 반원의 방향에 따라 적절히 크기를 조절

 

<corners> 태그에서 

topLeftRadius 왼쪽 상단 둥글게

topRightRadius 오른쪽 상단 둥글게

bottomLeftRadius 왼쪽 하단 둥글게

bottomRightRadius 오른쪽 하단 둥글게

 

수정하면서 모양을 보면 쉽게 할 수 있다.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/red"/>
    <size
        android:width="5dp"
        android:height="10dp"/>
    <corners
        android:bottomRightRadius="20dp"
        android:topRightRadius="20dp"/>
</shape>

 

 

Posted by Lumasca
,

scale: 뷰의 크기을 조절하여 심장이 뛰는 것처럼 커졌다  작아졌다하는 것과 같은 효과를 낼 수 있다.

android:duration 은 애니메이션 적용시간이며, 밀리세컨드 단위이다.
android:fromXScale 은 X축의 시작시점 크기이다.
android:fromYScale 은 Y축의 시작시점 크기이다.
android:pivotX 은 X축 중심점 좌표이다.
android:pivotY 은 Y축 중심점 좌표이다.
android:toXScale 은 X축의 종료시점 크기이다.
android:toYScale 은 Y축의 종료시점 크기이다.

 

X축는 수평방향, Y축는 수직방향이다.

1.0은 변경이 없다는 의미이다.

 

res/anim 폴더에 bounce_circle.xml 로 아래와 같이 작성한다.

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.6"
    android:toYScale="0.6" />

 

위에서 작성한 애니메이션을 적용해 반복해서 바운스 효과를 내는 코드

val aniBounce = AnimationUtils.loadAnimation(mContext, R.anim.bounce_circle)
val interpolator = BounceInterpolator()
aniBounce.interpolator = interpolator
aniBounce.repeatCount = Animation.INFINITE
aniBounce.repeatMode = Animation.REVERSE
        
imgCircleBounce.startAnimation(aniBounce)

interpolator: 애니메이션 효과를 가속하거나 감속 또는 반복하는등 여러가지 효과를 낼 수 있다. BounceInterpolator를 주어서 심장이 뛰는 것과 같은 효과를 주었다.

참고: https://developer.android.com/guide/topics/resources/animation-resource#Interpolators

 

애니메이션 리소스  |  Android 개발자  |  Android Developers

애니메이션 리소스는 다음 두 가지 유형의 애니메이션 중 하나를 정의할 수 있습니다. 속성 애니메이션 설정된 시간 경과에 따른 객체의 속성 값을 Animator로 수정하여 애니메이션을 만듭니다. ��

developer.android.com

repeatCount는 반복회수인데 Animation.INFINITE(-1)로 설정하면 무한 반복이다. 또는 양의 정수로 설정한다. 0은 반복없음으로 한번 효과를 내고 끝나며, 1은 효과를 한번더 반복하는 것이다.

repeatMode는 repeatCount가 INFINITE여야 한다. 반복할때 애니메이션을 역방향으로 적용하려면 REVERSE를, 처음 위치부터 다시 적용하려면 RESTART를 적용한다.

fillAfter: 애니메이션 종료후에 상태를 설정한다. true는 종료후에 변형을 유지한다. false는 종료후에 변형을 유지하지 않고  원래대로 복원한다.

fillBefore: 애니메이션 시작전에 상태를 설정한다. true는 시작전에 변형을 적용한다. false는 시작전에 변형을 적용하지 않는다.

 

translate : https://lumasca.tistory.com/609

 

 

 

'개발 > Android' 카테고리의 다른 글

Android Studio Firebase Crashlytics 설정  (0) 2020.05.13
반원(half circle) xml  (0) 2020.05.11
Android Animation translate  (0) 2020.05.08
google service 빌드 오류  (0) 2020.05.04
오류: Cannot inline bytecode built with JVM target 1.8 ..  (0) 2020.01.07
Posted by Lumasca
,

translate: 뷰를 왼쪽, 오른쪽, 위, 아래로 이동하는 효과를 낸다.

 

 fromXDelta : X축의 시작 위치
 toXDelta : X축의 종료 위치
 fromYDelta : Y축의 시작 위치
 toYDelta : Y축의 종료 위치 

 

설정 값의 범위

-자신을 기준으로 -100 ~ 100 의 '%'로 끝나는 값: '100%'

-상위요소를 기준으로 -100 ~ 100 의 '%p'로 끝나는 값: '100%p'

-부동소수점(절대값)

 

이미지뷰가 위아래로 반복해서 움직이면서 오른쪽에서 왼쪽으로 부모 뷰의 절반 정도 이동했다가 다시 오른쪽으로 이동해서 멈추는 효과

 

투명도를 적용한 이미지뷰를 바운스를 시킬 것이고

해당 이미지뷰를 감싼 레이아웃은 수직으로 움직을 것이다. height가 wrap_content이다.

그리고 수직으로 움직이는 레이아웃을 감싸서 수평으로 움직일 것이다. width가 wrap_content이다.

최상위 레이아웃은 gravity 은 설정하지 않는다.

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <LinearLayout
            android:id="@+id/layoutCardCircleHorz"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            >
        <RelativeLayout
            android:id="@+id/layoutCardCircleVert"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">

            <ImageView
                android:id="@+id/imgCircle"
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_centerInParent="true"
                android:src="@drawable/btn_login_bn"
                />

            <ImageView
                android:id="@+id/imgCircleBounce"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:alpha="0.2"
                android:layout_centerInParent="true"
                android:background="@drawable/circle_yellow" />
        </RelativeLayout>
    </LinearLayout>
    </RelativeLayout>

repeatCount는 반복회수인데 Animation.INFINITE(-1)로 설정하면 무한 반복이다. 또는 양의 정수로 설정한다. 0은 반복없음으로 한번 효과를 내고 끝나며, 1은 효과를 한번더 반복하는 것이다.

repeatMode는 repeatCount가 INFINITE여야 한다. 반복할때 애니메이션을 역방향으로 적용하려면 REVERSE를, 처음 위치부터 다시 적용하려면 RESTART를 적용한다.

//위아래 반복 애니메이션
val animUpDown = TranslateAnimation(
                Animation.RELATIVE_TO_PARENT,0f,
                Animation.RELATIVE_TO_PARENT, 0f,
                Animation.RELATIVE_TO_PARENT, -0.2f,
                Animation.RELATIVE_TO_PARENT, 0.2f)
animUpDown.duration = 300
animUpDown.repeatCount = Animation.INFINITE
animUpDown.repeatMode = Animation.REVERSE

layoutCardCircleVert.startAnimation(animUpDown)

//왼쪽으로 이동 애니메이션
val aniLeft = TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_PARENT, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, -0.4f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f)
//RELATIVE_TO_PARENT(상위요소기준), RELATIVE_TO_SELF(자신), ABSOLUTE(절대값)
aniLeft.duration = 2000 //애니메이션 적용시간

//오른쪽 이동 애니메이션
val aniRight = TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_PARENT, -0.4f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f)
        aniRight.duration = 2500
        
        aniLeft.setAnimationListener(object : Animation.AnimationListener{
            override fun onAnimationEnd(animation: Animation?) {
                //왼쪽이동이 끝나면 오른쪽으로 이동 애니 시작
                layoutCardCircleHorz.startAnimation(aniRight)
            }

            override fun onAnimationStart(animation: Animation?) {

            }

            override fun onAnimationRepeat(animation: Animation?) {

            }
        })

        aniRight.setAnimationListener(object: Animation.AnimationListener{
            override fun onAnimationEnd(animation: Animation?) {
                //오른쪽 이동이 끝나면 위아래 반복 중지
                layoutCardCircleVert.clearAnimation()
                //바운스 시작
                imgCircleBounce.startAnimation(aniBounce)
            }

            override fun onAnimationStart(animation: Animation?) {

            }

            override fun onAnimationRepeat(animation: Animation?) {

            }
        })
//왼쪽 이동 애니 시작        
layoutCardCircleHorz.startAnimation(aniLeft)


scale이용한 바운스 효과: https://lumasca.tistory.com/610

'개발 > Android' 카테고리의 다른 글

반원(half circle) xml  (0) 2020.05.11
Android Animation scale  (0) 2020.05.08
google service 빌드 오류  (0) 2020.05.04
오류: Cannot inline bytecode built with JVM target 1.8 ..  (0) 2020.01.07
Android Studio Configuration이 없을때..  (0) 2020.01.04
Posted by Lumasca
,
설치해야할 항목들이다.

1. JDK (http://java.sun.com/javase/downloads/index.jsp)
  64비트 OS라도 x86 용으로 설치해야한다. 

  설치라기 보단 특정폴더에 압축을 푼다.

SDK 메뉴로 이동해서 최신버전을 다운받고 압축을 풀도록 한다.
이클립스를 실행하고, Window->Preference 메뉴를 클릭, Androide 탭을 선택한다.
Browse를 클릭하고 SDK가 설치된 폴더(포함)를 선택하고 Apply 를 클릭한다.

5. ADT
이클립스를 실행하고, Help -> SoftUpdate 메뉴를 선택한다.
Add Site.. 버튼을 클릭하고, http://dl-ssl.google.com/android/eclipse/ 을 붙여넣고 OK를 누른다.
항목에 해당 URL이 생기고, 탐색을 하면 ADT 플러그인을 선택할 수 있다.
나머지는 선택하고 업데이트...


'개발 > Android' 카테고리의 다른 글

Android Animation scale  (0) 2020.05.08
Android Animation translate  (0) 2020.05.08
google service 빌드 오류  (0) 2020.05.04
오류: Cannot inline bytecode built with JVM target 1.8 ..  (0) 2020.01.07
Android Studio Configuration이 없을때..  (0) 2020.01.04
Posted by Lumasca
,