consp1racy / android-support-preference

Android Preferences according to Material design specs
Apache License 2.0
331 stars 49 forks source link

How to add dividers between preference groups #79

Closed tcqq closed 7 years ago

tcqq commented 7 years ago

material design specification the dividing line should be added below the grouping,how to add the division line below the group?

Like this: https://material.io/guidelines/patterns/settings.html#settings-usage

consp1racy commented 7 years ago

Readme has a section about dividers. If that doesn't answer your question, please, come back here and let me know.

tcqq commented 7 years ago

How to achieve this picture the dividing line? https://material.io/guidelines/patterns/settings.html#settings-usage

consp1racy commented 7 years ago

https://github.com/consp1racy/android-support-preference#dividers

https://github.com/consp1racy/android-support-preference/blob/653eaaf5ff756fbff016532b0a54d64e1e78247a/sample/src/main/java/net/xpece/android/support/preference/sample/SettingsFragment.java#L264-L275

tcqq commented 7 years ago

I tested it, but the effect is different

consp1racy commented 7 years ago

Please post a screenshot of what you currently have and highlight desired changes.

tcqq commented 7 years ago

image.zip

consp1racy commented 7 years ago

Don't copy paste, look at the PreferenceDividerDecoration API and source and pick what's best for your case. Understand what the code does:

listView.addItemDecoration(new PreferenceDividerDecoration(getContext()).drawBottom(false).drawBetweenItems(false));
setDivider(null);

Preference categories without title are currently not possible.

Extra spacing around dividers is something I can do.

EDIT

Good news! You will be able to do both these things in the next version.

image

tcqq commented 7 years ago

Cool, thank you

tcqq commented 7 years ago

now seedbar the xml have problem,ImageView the maxHeight and maxWidth invalid because not add this code: “android:adjustViewBounds="true"”

consp1racy commented 7 years ago

You can now achieve what's shown on the material design settings screenshot.

SettingsFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final RecyclerView listView = getListView();

    final int padding = (int) TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    listView.setPadding(0, padding, 0, padding);

    // We're using alternative divider.
    listView.addItemDecoration(new PreferenceDividerDecoration(getContext())
        .drawBetweenItems(false).paddingDp(listView.getContext(), 8));
    setDivider(null);

    // We don't want this. The children are still focusable.
    listView.setFocusable(false);
}

You may also wrap preferences in preference categories without title

preferences.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory>
        <!-- Put a preference here. -->
    </PreferenceCategory>
</PreferenceScreen>

This has been released in v1.3.0.

tcqq commented 7 years ago

Ok thank you