2

I am creating an android project. I am using PreferenceCategory in my PreferenceScreen. My layout for PreferenceScreen looks like this.

<PreferenceCategory app:title="ABC"
        app:key="P1"
        />
<PreferenceCategory app:title="ABC"
        app:key="P2"
        />
<PreferenceCategory app:title="ABC"
        app:key="P3"
        />
<PreferenceCategory app:title="ABC"
        app:key="P4"
        />
<PreferenceCategory app:title="ABC"
        app:key="P5"
        />

In PreferenceCategory P2 and P3 I am adding Preferences using addPreference() function. What I want is to show PreferenceCategory P4 and P5 in centre(horizontally and vertically) of remaining screen.

I searched on internet about this but didn't find any gravity related attribute for PreferenceCategory. Is there any way to achieve this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Vivek Mangal
  • 532
  • 1
  • 8
  • 24
  • My suggestion would be not using a preference screen and rather designing your own layout. Because preference screens are supposed to be made scrollable if the content is bigger than the screen. It mostly has a `ListView` or a `RecyclerView` to show the content which blocks you from placing any gravity on the child view. – Furkan Yurdakul Mar 19 '20 at 13:53
  • The behaviors can still be implemented manually, however it looks like you need to change your whole structure. – Furkan Yurdakul Mar 19 '20 at 13:53
  • I added a custom layout for preference category with a single textview in it and with attribiute android:layout_gravity="center_horizontal|center_vertical but textview comes after much scrolling – Vivek Mangal Mar 19 '20 at 14:52
  • Hello. I didn't get how to use custom layout as it is my settings activity and i have to use preferences. How can I use preferences outside preference screen – Vivek Mangal Mar 20 '20 at 15:11
  • what furkan is proposing is that you dont use the preference framework at all and just create your own activity for it. using a SharedPreferences editor you can achieve the same that your preferences achieve but with a lot more work haha – quealegriamasalegre Mar 31 '20 at 05:42
  • might help https://stackoverflow.com/questions/55371906/androidx-preference-screen-shifted-off-center – Shubham Apr 06 '20 at 09:57
  • @FurkanYurdakul . you were right. Finally had to design my own layout instead of using preferences. Thank you guys for help. – Vivek Mangal May 23 '20 at 14:21

0 Answers0