【问题标题】:PreferenceScreen android:paddingTop not workingPreferenceScreen android:paddingTop 不起作用
【发布时间】:2015-04-01 00:55:21
【问题描述】:

使用普通布局文件,我可以像这样设置顶部填充

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"

>

但是,使用首选项屏幕时,它会使填充不足一些像素(操作栏为 168 dp,但填充仅显示 144),知道如何解决这种跨设备方式。谢谢。

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingTop="?attr/actionBarSize">

【问题讨论】:

    标签: android android-actionbar preferencefragment


    【解决方案1】:

    使用PreferenceScreen 时,您无权访问这些xml 属性。但是你可以做的是给它添加这个属性:

    android:layout="@layout/header_setting"
    

    然后创建一个在本例中称为“header_settings”的 XML 布局文件,您可以像往常一样更改大小和填充。但是将 id 应用于 PreferenceScreen 知道标题或图标的位置的元素。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="match_parent"
        android:padding="0dp"
        android:layout_height="match_parent">
    
        <ImageView
            android:id="@+android:id/icon"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="15dp"
            android:layout_width="40dp"
            android:layout_height="40dp" />
    
        <TextView android:id="@+android:id/title"
            android:layout_marginLeft="80dp"
            android:textColor="#000"
            android:layout_marginTop="23dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"/>
    </LinearLayout>
    

    现在这里是一个关于 PreferenceScreen 应该是什么样子的示例:

        <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout="@layout/pref_screen">
    
    
        <PreferenceCategory>
            <PreferenceScreen
                android:icon="@drawable/setting_star"
                android:layout="@layout/header_setting"
                android:title="Upgrade to Pro!">
    
            </PreferenceScreen>
        </PreferenceCategory>
    </PreferenceScreen>
    

    请注意您只能访问以下属性:标题、摘要和图标。布局属性允许您将其自定义为您想要做的任何事情。在 XML 中,您必须保持 id 相同,因为 PreferenceScreen 知道这是放置标题文本或图标图像的方式。

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多