2011-10-06 95 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,你能解釋一下如何從畫廊或相機設置圖片來定製佈局,點擊偏好是這樣嗎? –