2015-04-01 117 views
0

与正常布局文件,我可以设置填充顶部这样PreferenceScreen安卓:paddingTop不工作

<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"> 

回答

1

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

android:layout="@layout/header_setting" 

然后创建一个名为在这个例子中的XML布局文件“header_settings”你可以改变大小和填充为正常。但是,将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知道如何放置标题文本或图标图像。

我希望这有助于!