2011-10-06 46 views
1

他是我喜欢的活动:如何在PreferenceActivity中添加ImageView?

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen 
    xmlns:android="http://schemas.android.com/apk/res/android"> 


     <PreferenceCategory 
      android:title="Select your country or region"> 
       <ListPreference 
       android:title="Pick your country" 
       android:key="regionsListPref" 
       android:defaultValue="digiGreen" 
       android:entries="@array/regionArray" 
       android:entryValues="@array/regionValues" /> 

       <ImageView 
     android:id="@+id/ImageView01" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:cropToPadding="true" 
     android:adjustViewBounds="true" 
     android:src="@drawable/splash" 
     android:scaleType="centerInside"></ImageView> 

     </PreferenceCategory> 

    <PreferenceCategory 
      android:title="Second Category"> 
     <CheckBoxPreference android:title="@string/bjr" android:key="macheckbox" 
     android:summaryOn="La checkbox est cochée" 
     android:summaryOff="La checkbox n'est plus cochée" 
     android:defaultValue="true" 
     /> 

     <EditTextPreference android:title="Mon EditText" 
     android:dialogTitle="Modification du texte" 
     android:dialogMessage="Entrez le nouveau texte" 
     android:dialogIcon="@drawable/icon" 
     android:defaultValue="Texte par défaut" android:key="montextedit"/> 
     </PreferenceCategory> 

</PreferenceScreen> 

随着MMY代码生成项目时,有没有错误。 但是,我通过显示首选项活动来运行它时遇到了异常。

所以,我的问题是:如何简单地将ImageView添加到PreferenceActivity中?

最好的问候

回答

2

有没有简单的方法来做到这一点。您的偏好活动需要一个Preference或扩展它的类,以便在您提供的其他类上崩溃。

我从来没有这样做之前,但这里是我想尝试:

  • 把一个默认Preference到您设置的XML
  • 创建资源自定义布局(与自己的倒影)
  • 使用android:layout属性在设置中设置自定义布局XML

在首选项上设置自定义布局时可能会有一些陷阱ase阅读setLayoutResource。你可以看看the default layout是如何组成的。

+0

Tnx Knickedi,你能解释一下如何从画廊或相机设置图片来定制布局,点击偏好是这样吗? –