ToDoList
1.0.0
appetize.io의 라이브 데모
Dribbble에서 이 프로젝트를 확인하세요.
블로그에서 우리가 어떻게 했는지 읽어보세요
##요구사항
##용법
루트 build.gradle에 추가합니다.
allprojects {
repositories {
.. .
maven { url " https://jitpack.io " }
}
}
종속성을 추가합니다.
dependencies {
compile ' com.github.yalantis:todolist:v1.0.1 '
}
XML 레이아웃에 BatRecyclerView
추가
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< LinearLayout xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : app = " http://schemas.android.com/apk/res-auto "
android : id = " @+id/root "
android : layout_width = " match_parent "
android : layout_height = " match_parent "
android : background = " @drawable/gradient "
android : orientation = " vertical " >
< android .support.v7.widget.Toolbar
android : id = " @+id/toolbar "
android : layout_width = " match_parent "
android : layout_height = " ?android:attr/actionBarSize "
android : background = " @android:color/transparent "
app : logo = " @drawable/ic_menu " >
< TextView
android : id = " @+id/text_title "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_gravity = " center "
android : text = " 14 Feb, 2016 "
android : textColor = " @android:color/white "
android : textSize = " 20sp " />
</ android .support.v7.widget.Toolbar>
< com .yalantis.beamazingtoday.ui.widget.BatRecyclerView
android : id = " @+id/bat_recycler_view "
android : layout_width = " match_parent "
android : layout_height = " match_parent "
android : layout_gravity = " center_horizontal "
app : add_button_color = " @drawable/selector_button_add "
app : hint = " @string/str_add_goal "
app : radio_button_res = " @drawable/selector_radio_button " />
</ LinearLayout >
BatListener
생성
private BatListener mListener = new BatListener () {
@ Override
public void add ( String string ) {
mGoals . add ( 0 , new Goal ( string ));
mAdapter . notify ( AnimationType . ADD , 0 );
}
@ Override
public void delete ( int position ) {
mGoals . remove ( position );
mAdapter . notify ( AnimationType . REMOVE , position );
}
@ Override
public void move ( int from , int to ) {
if ( from >= 0 && to >= 0 ) {
//if you use 'BatItemAnimator'
mAnimator . setPosition ( to );
BatModel model = mGoals . get ( from );
mGoals . remove ( model );
mGoals . add ( to , model );
mAdapter . notify ( AnimationType . MOVE , from , to );
if ( from == 0 || to == 0 ) {
mRecyclerView . getView (). scrollToPosition ( Math . min ( from , to ));
}
}
}
};
BatAdapter
생성합니다. 모델의 생성자 목록과 BatListener
에 전달합니다. 모델은 BatModel
인터페이스를 구현해야 합니다.
mAdapter = new BatAdapter ( mGoals = new ArrayList < BatModel >() {{
add ( new Goal ( "first" ));
add ( new Goal ( "second" ));
add ( new Goal ( "third" ));
add ( new Goal ( "fourth" ));
add ( new Goal ( "fifth" ));
add ( new Goal ( "sixth" ));
add ( new Goal ( "seventh" ));
add ( new Goal ( "eighth" ));
add ( new Goal ( "ninth" ));
add ( new Goal ( "tenth" ));
}}, mListener );
mAdapter . setOnItemClickListener ( new OnItemClickListener () {
@ Override
public void onClick ( BatModel item , int position ) {
Toast . makeText ( ExampleActivity . this , item . getText (), Toast . LENGTH_SHORT ). show ();
}
});
재활용 보기 초기화
mRecyclerView . getView (). setLayoutManager ( new LinearLayoutManager ( this ));
mRecyclerView . getView (). setAdapter ( mAdapter );
ItemTouchHelper itemTouchHelper = new ItemTouchHelper ( new BatCallback ( this ));
itemTouchHelper . attachToRecyclerView ( mRecyclerView . getView ());
mRecyclerView . setAddItemListener ( mListener );
데모에서처럼 BatItemAnimator
사용하여 목록 항목에 애니메이션을 적용할 수 있습니다.
mAnimator = new BatItemAnimator ();
mAdapter = new BatAdapter ( mGoals = new ArrayList < BatModel >() {{
add ( new Goal ( "first" ));
add ( new Goal ( "second" ));
add ( new Goal ( "third" ));
add ( new Goal ( "fourth" ));
add ( new Goal ( "fifth" ));
add ( new Goal ( "sixth" ));
add ( new Goal ( "seventh" ));
add ( new Goal ( "eighth" ));
add ( new Goal ( "ninth" ));
add ( new Goal ( "tenth" ));
}}, mListener , mAnimator );
mRecyclerView . getView (). setItemAnimator ( mAnimator );
애니메이터 인스턴스를 BatRecyclerView
및 BatAdapter
에 전달해야 합니다. 또한 move()
콜백에서 이동된 항목의 위치를 전달해야 합니다.
@ Override
public void move ( int from , int to ) {
if ( from >= 0 && to >= 0 ) {
mAnimator . setPosition ( to );
BatModel model = mGoals . get ( from );
mGoals . remove ( model );
mGoals . add ( to , model );
mAdapter . notify ( AnimationType . MOVE , from , to );
if ( from == 0 || to == 0 ) {
mRecyclerView . getView (). scrollToPosition ( Math . min ( from , to ));
}
}
}
더 많은 사용 예를 보려면 샘플 앱을 검토하세요.
cursor_drawable
속성 및 setCursorDrawable(@DrawableRes int res)
메소드가 추가되었습니다. 각각 cursor_color
속성 및 setCursorColor(@ColorInt int color)
메소드 대신 사용해야 합니다. 귀하가 우리 구성요소를 사용하는 프로젝트에 대한 링크를 보내주시면 정말 기쁠 것입니다. [email protected]으로 이메일을 보내주세요. 애니메이션에 관한 질문이나 제안 사항이 있으면 알려주세요.
PS 우리는 코드로 싸인 더 멋진 기능과 iOS(Android)용 UI를 더 좋게 만드는 방법에 대한 튜토리얼을 게시할 예정입니다. 계속 지켜봐 주시기 바랍니다!
The MIT License (MIT)
Copyright © 2017 Yalantis, https://yalantis.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.