如何在android中正确对齐PreferencesActivity? [英] How to right align PreferencesActivity in android?

查看:38
本文介绍了如何在android中正确对齐PreferencesActivity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 PreferencesActivity 我需要它右对齐,因为我想使用阿拉伯语,我尝试使用 android:layout_gravity="right" 作为 >PreferenceScreen 但它不起作用.

I have PreferencesActivity which I need it to be right aligned because I want to use Arabic language, I tried to use android:layout_gravity="right" for PreferenceScreen but it didn't work.

这是我的 XML:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="right">
        <PreferenceCategory android:title="General Settings">
                <CheckBoxPreference
                        android:title="Full Screen"
                        android:defaultValue="false"
                        android:summary="Always view as Full Screen"
                        android:key="fullScreenPref" />
        <Preference
                android:title="Report Bugs"
                android:summary="Notify us for any Bugs or Errors"
                android:key="bugs"/>
        <Preference
                android:title="About"
                android:summary="Version 1.0.0"
                android:key="about"/>
        </PreferenceCategory>
</PreferenceScreen>

这就是我在 PreferencesActivity 中使用 XML 的方式:

This is how I use the XML inside PreferencesActivity:

addPreferencesFromResource(R.layout.preferences);

推荐答案

不幸的是基础 Preference 组件 (PreferenceScreenPreference 等)以一种相当不可配置的方式实现.它们旨在以特定方式工作,并且不是非常可定制的.

Unfortunately the base Preference components (PreferenceScreen, Preference, etc.) are implemented in a fairly non-configurable way. They are designed to work in a specific way and are not terribly customizable.

为了做您想做的事,您可能必须实现您自己的 PreferenceScreen 版本(或者可能只是您正在使用的 Preference 类型,例如 CheckBoxPreference).它的设计方式是,当它膨胀 XML 布局时,它会假设很多关于它们的事情并为您处理(文本大小、填充、布局、换行等).如果您希望它看起来像默认值,这很好,但如果您需要调整这些配置,那就不是很好了.

In order to do what you want, you will probably have to implement your own version of PreferenceScreen (or possible just the Preference types you are using such as CheckBoxPreference). The way it is designed, when it inflates XML layouts it assumes a lot of things about them and handles it for you (text size, padding, layout, wrapping, etc). This is great if you want it to look like the default, but not so great if you need to tweak these configurations.

(注意:如果您不想实现首选项屏幕,您可以只使用列表视图并将其视为首选项页面.但是,无论哪种方式,您基本上都必须实现自己的首选项版本.)

(note: if you don't want to implement preferencescreen you could just use a listview and treat it as a preference page. However, either way you basically have to implement your own version of preferences.)

(注 2:根据我看到的有关阿拉伯文本的其他问题,可能 android 足够聪明,可以尝试默认右对齐它.但是,如果这是情况.不过,值得一试.)

(note2: based on other questions I've seen about arabic text, it's POSSIBLE android is smart enough to try to right align it by default. However, I would be surprised if this was the case. Still, it's worth a try.)

抱歉,我没有更好的答案给您.

Sorry I don't have a better answer for you.

这篇关于如何在android中正确对齐PreferencesActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆