너무 가늘어서 전달할 수 없는 Material Design 설치

9396 단어 Android
당신의 보살핌을 받았습니다.@seto_hi.
안드로이드 엔지니어들에게는 오늘도 머티리얼 디자인 설치에 많은 소모가 있었다.
오늘은 머티리얼 디자인 가이드라인의 커버 박스를 소개해 드리는데 혹시 참고할 만한 오류가 있으면 좋겠습니다.
코드가 전부 여기 창고 올랐다.

List의 Top padding 및 Bottom padding


읽었다가이드라인의 Lists.'Add8dp of padding at the top and bottom of a list'라는 표현이 12번 나왔다.
RecyclearView의 paddingToppaddingBottom로 간단하게 해결하면
스크롤 경계의 효과는 패딩 아래에서 바뀌었습니다. 스크롤할 때 항목이 잘려서 보기 싫습니다.
여기서는 혼자만의 아이템 디코레이션을 만들어 해결하자!
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.top += mPadding;
        } else if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
            outRect.bottom += mPadding;
        }
    }

이렇게 하면 완벽해!

문자 크기(Dense)


읽었다안내서의 Typolaphy 일본어가'덴서'로 분류된다고 적혀 있었다.
그러나 Support Library에는 Dense의 Text Apperance가 없습니다.
만들자.
<style name="TextAppearance.AppCompat.Body1.Dense" parent="TextAppearance.AppCompat.Body1">
    <item name="android:textSize">15sp</item>
</style>
xml의 전체 보기github.
이렇게 TextView에 적용
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1.Dense" />

NavigationDrawer의 item Background


읽기설명서의 Navigation Drawer 후 선택하지 않은 항목이 있으면 Ripple Effect가 표시되고 선택한 항목에는 배경색이 회색인 아트웍이 표시됩니다.
Design Support LibraryNavigationView를 사용하면 아무것도 하지 않아도 되지만, 여러 가지 상황에 따라 RecyclearView를 사용해 맞춤 제작을 하려면 번거롭다.
Item의 Viewandroid:background="?attr/selectableItemBackground"에서도 선택한 배경색이 표시되지 않습니다.
그럼에도 리플에펙트와 선택색을 결합한 State Listrawarble가 직접 만들어도 골치가 아프다.
Layer Drawable을 사용합니다.
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.selectableItemBackground, value, true);
Drawable top = ContextCompat.getDrawable(getContext(), value.resourceId);
Drawable back = ContextCompat.getDrawable(getContext(), R.drawable.bg_checkable_list_item);
Drawable itemBackground = new LayerDrawable(new Drawable[]{back, top});
R.drawable.bg_checkable_list_item
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/bgListItemChecked" android:state_checked="true" />
    <item android:drawable="@android:color/transparent" />
</selector>
그러면 색상 선택 부분의 State ListDrawable만 만들면 됩니다.
참고로 NavigationView는 Foreground Drawable에 대응하는 Linker Layout, foreground?attr/selectableItemBackground를 설치했고, background는 상기 State ListDrawable를 설정했다.그리고 State List Drawarble는 참조?attr/colorControlHighlight를 위해 자바에서 고릴라를 생성하고 있습니다.그렇구나!

Auto Loading


실현하고 싶은데가이드라인의 Progress &activity의 Two-phased loads 같은 loading.,RecyclearView가 소박하면 귀찮지 않습니까?
어댑터에 설치하려면ListViewHeaderViewListAdapter처럼 어댑터 in 어댑터가 되지만, 저는 잘 안 어울려요.
여기도 혼자만의 아이템 디코레이션을 만들어 해결하자!
ItemDecoration의 한계에 도전하는 것이 아니라 무엇이 옳은가.
요약 구현 후
  • Item Decoration+Drawable 애니메이션으로 해결
  • 고유한 Item Decoration에서 구현Drawable.Callback
  • Handler는 RecyclearView
  • 를 사용합니다.
    이런 일을 하면서.자세한 설치는 github를 참조하십시오.
    참고로 현지 호칭RecyclerView#removeItemDecoration에 불편하면 메모리가 유출됩니다!

    최후


    최고!최고!
    머티리얼 디자인 설치에는 아직 허점이 많지만, 몸을 가루로 갈아 구현해 사용자를 행복하게 해주세요!

    좋은 웹페이지 즐겨찾기