728x90
반응형

기존에 Android에서 제공하는 DrawerLayout은 아래와 같이 기존 화면 위에 올라오는 방식이다.


  


(출처: http://frogermcs.github.io/InstaMaterial-concept-part-7-navigation-drawer/)

(출처: http://www.journaldev.com/12648/navigationview-android)



하지만 오늘 소개하고자 하는 Library는 DrawerLayout과는 반대로 기존 화면이 움직이는 방식이다.


일단 말로만 들으면 무슨소리인지 모르니 아래 그림을 보자.

(출처: https://github.com/yarolegovich/SlidingRootNav)


어떤가요? 너무 신기하지 않나요?

저는 매우 신기해서 제 앱에도 넣었습니다.




자 이제 SlidingRootNav가 어떤건지 알았으니 사용해봅시다.


app Module build.gradle파일에 dependency를 추가해줍니다.

dependencies {
compile 'com.yarolegovich:sliding-root-nav:1.0.2'
}


샘플을 위헤 Activity에 들어갈 layout과 SlidingRootNav로 사용할 layout을 준비합니다.


main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:orientation="vertical"
tools:context="com.googry.googryslidingrootnav.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!"
android:textColor="@android:color/white"
android:textSize="30dp"/>

</FrameLayout>


sliding_root_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="Sliding\nRoot\nNav"
android:textColor="@android:color/black"
android:textSize="30dp"/>

</FrameLayout>


MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.sliding_root_nav)
.inject();
}
}

이렇게 하면 기본적인것은 끝이 납니다.


아주아주 기본예제인 것이죠.



하지만 지금은 햄버거 버튼도 없고 우리가 위에서 봤던 Toolbar가 같이 움직이는 그림은 아닙니다.

(뭐야 그럼 어떻게 해야하는거야?)


그럼 이제 툴바도 같이 움직이게 해봅시다.


일단 기본 테마에서 ActionBar를 제거하고 Title도 제거해줍시다.

parent를 Theme.AppCompat.Light.NoActionBar로 변경해도 상관없습니다.

(액션바만 없어져라!)


styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
</style>

</resources>

그 다음에는 main_activity.xml에 Toolbar를 추가해줍시다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:orientation="vertical"
tools:context="com.googry.googryslidingrootnav.MainActivity">


<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>


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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!"
android:textColor="@android:color/white"
android:textSize="30dp"/>

</FrameLayout>

</LinearLayout>

MainActivity.java에서 Toolbar를 연결해줍시다.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.sliding_root_nav)
.inject();
}
}


이제는 Toolbar도 같이 움직입니다!


(아직 햄버거 버튼이 없잖아...)



이제 햄버거 버튼도 넣어봅시다.


햄버거 버튼은 SlidingRootNavBuilder에서 withToolbarMenuToggle()을 추가해주면 됩니다.

참 쉽죠?

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);

new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.sliding_root_nav)
.withToolbarMenuToggle(toolbar)
.inject();
}
}



Toolbar에 title과 햄버거 버튼 색깔은 아래코드를 추가하면 바꿀수 있습니다.


툴바 타이틀 색변경


toolbar.setTitleTextColor(Color.WHITE);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);


툴바 햄버거 색 변경

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<item name="colorButtonNormal">@android:color/white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>


제가 만들고 있는 코인원헬퍼에는 이런식으로 적용했습니다.




위에서 작성한 코드들은 아래 깃허브에서 다운받아보실 수 있습니다.

https://github.com/sjjeong/GoogrySlidingRootNav



SlidingRootNav에 대한 더 많은 정보는 아래 깃허브 페이지에서 확인 할 수 있습니다.

https://github.com/yarolegovich/SlidingRootNav


스타도 꼭 눌러줍시다!


728x90
반응형

'Android > Library' 카테고리의 다른 글

(Android) 고품질 애니메이션을 위한 Lottie Library  (3) 2017.08.01
728x90
반응형

오늘은 매운 라멘을 먹기위해 성신여대에 있는 매운라멘집! 마카나이(MAKANAI)에 갔다.



가게 안에는 두명씩 앉을 수 있는 테이블이 총 6개가 있었고 4명이 일렬로 앉아서 먹을 수 있는 테이블 하나가 있다.



나는 그중 일렬로 앉을 수 있는 테이블에 앉았다.


테이블에는 김치와 단무지가 준비되어있다.



매운맛 레벨이 1단계부터 15단계까지 있는데 2단계가 신라면 정도라면...


나는 3단계에서 4단계를 고민하다가 매운거도 잘 못먹고 해서 그냥 3단계를 주문하고 차슈도 추가를 했다.



라멘이 나왔을때 처음 비주얼은 별로 안매울거 같다고 생각을 했다.


일단 국물을 먼저 먹었을때 약간 신라면에 계란 2개정도 풀었을 때 맛이었다.

매운맛의 정도도 딱 신라면에 고추가루 좀더 넣었을때 그런 매운맛이었다.


차슈는 정말 부드럽고 맛있었다.

개인적으로 차슈만 따로 먹고싶을 정도로..


국물을 계속 먹다보니 정말 고소하고 담백하고 진짜 맛있었다.

면은 솔직히 잘 모르겠다.



괜찮아 보여서 한컷!



마카나이 메뉴







마카나이 위치

서울특별시 성북구 보문로30길 72 선희빌 1층



네이버 지도로 보기

728x90
반응형
728x90
반응형

애니메이션 효과는 앱의 품질을 높여주는 역할을 하며 사용자에게 더 좋은 UI/UX를 제공합니다. 


(출처: https://github.com/airbnb/lottie-android)


그렇다면 이제 Lottie에 대해 알아보고 사용법에 대해 알아보자.


Lottie란?

Lottie는 Airbnb에서 만들었고 실시간으로 After Effect 애니메이션을 랜더링하고 iOS, Android, React Native에서 동작하는 고품질 애니메이션 라이브러리입니다.




그럼 After Effect에서 만든 파일은 .aep나 .aepx인데 이것을 안드로이드에서 바로 가져다가 쓸 수 있나?

아니요. 바로 가져다가 쓸 수 없습니다.


그래서 Bodymovin이라는 After Effect Plugin을 설치해서 안드로이드에서 사용할 수 있는 파일로 변환 해 줘야합니다.


Bodymovin을 사용하면 애니메이션을 JSON 데이터 포맷으로 추출 할 수 있고 이것을 가져다가 안드로이드에서 보여주면 됩니다.


그럼 이제 안드로이드에서 Lottie를 추가하고 사용하는 법에 대해 알아보자.


app Module build.gradle파일에 dependency을 추가해줍니다.

dependencies {
compile 'com.airbnb.android:lottie:2.1.0'
}

그리고 project sync를 하면 lottie 라이브러리가 추가 된 것을 확인 할 수 있습니다.



layout에 LottieAnimationView를 추가합니다.

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_autoPlay="true"
app:lottie_fileName="data.json"
app:lottie_loop="true"/>


lottie_fileName은 After Effect에서 만든 애니메이션의 json파일 이름이 들어가야 합니다.

그리고 json파일은 assets폴더 안에 넣어줍니다.


lottie_autoPlay는 엑티비티가 실행되고 layout이 화면에 보여질때 자동으로 애니메이션을 시작하는 것이고

lottie_loop는 애니메이션이 끝나고 반복적으로 다시 실행 할지 결정하는 것입니다.


또한 autoPlay, fileName, loop와 같은 속성은 자바 코드로도 사용 할 수 있습니다.

LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);
animationView.setAnimation("data.json");
animationView.loop(true);
animationView.playAnimation();

그럼 결과는 아래와 같습니다.



LottieAnimationView에는 setProgress()를 사용해서 애니메이션의 offset을 바꾸거나 속도를 조절할 수 있습니다.







예제 샘플은 https://github.com/sjjeong/GoogryLottieSample 에서 확인 하실 수 있습니다.

예제에서 사용한 Lottie파일은 https://www.lottiefiles.com/ 에서 다운 받으실 수 있습니다.


추가로 애니메이션이 완료 된 후에 화면에서 사라지게 하고 싶으시다면 아래 코드를 확인해주세요.

final LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.lav_loading);
animationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onAnimationEnd(Animator animation) {
animationView.setVisibility(View.GONE);
}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

}
});


728x90
반응형

'Android > Library' 카테고리의 다른 글

(Android) DrawerLayout을 반대로? SlidingRootNav로 하자!  (0) 2017.08.13

+ Recent posts