问题描述
我的应用程序中有一个首选项屏幕,它偏离了中心,并且标题文本或数据不是从下图所示的左侧开始.我正在初始化设置片段.我尚未进行任何视觉更改或添加任何特殊属性.
I have a preference screen in my app and it is shifted off center and the header text or data doesn't start from the left shown in the image below. I am initializing the settings fragment. I have not applied any visual changes or added any special attributes.
父活动中没有填充或边距.我也有一个回收站视图,该视图在偏心状态下在应用程序中显示得很好
There is no padding or margin in the parent activity. I also have a recycler view which is displayed perfectly fine in the app with it being off centered
这是我的preferences.xml文件
This is my preferences.xml file
<androidx.preference.PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:title="General">
<Preference
app:key="feedback"
app:title="Send Feedback"
app:summary="Report technical issues or suggest new features"/>
<Preference
app:key="about"
app:title="About Us"/>
</PreferenceCategory>
<PreferenceCategory
app:title="Customize">
<SwitchPreferenceCompat
app:key="@string/key_darkTheme"
app:title="Enable Dark Theme"
app:summary="Enable dark theme throughout app (Restarts App Automatically)"
app:defaultValue="false"/>
<ListPreference
app:key="@string/key_font"
app:title="Set Font Size"
app:entries="@array/settings_list_preference_font"
app:entryValues="@array/settings_list_preference_values"
app:defaultValue="2"
app:summary="Set font size according to your liking"/>
</PreferenceCategory>
</androidx.preference.PreferenceScreen>
推荐答案
可能是因为首选项会自动为您提供图标空间.您可以通过在每个元素中使用app:iconSpaceReserved="false"
禁用空格来禁用该功能.
Probably because the preference automatically give you a space for an icon. You can disable that by disabling the space using app:iconSpaceReserved="false"
in each element.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:title="your_title"
app:iconSpaceReserved="false">
...
</PreferenceCategory>
</PreferenceScreen>
这篇关于AndroidX首选项屏幕偏离中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!