2011-05-24 76 views
0

在我的應用程序的主要活動中,我需要一個應該看起來像PreferencesActivity中的ListPreference的控件。我的意思是,2行:右側的標題和當前值以及向下箭頭圖標。優先項目樣佈局

我試着使用TwoLineListItem此:

<TwoLineListItem android:id="@+id/twoLineListItem1" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:onClick="onButtonClick" android:focusable="true" 
    android:background="@android:drawable/list_selector_background"> 
    <TextView android:layout_width="fill_parent" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_height="wrap_content" android:id="@android:id/text1" 
     android:text="Upload into:" /> 
    <TextView android:layout_below="@android:id/text1" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_alignLeft="@android:id/text1" android:layout_height="wrap_content" 
     android:id="@android:id/text2" android:text="&lt;not set&gt;" 
     android:layout_width="wrap_content" /> 
    <!-- <ImageView android:layout_width="wrap_content" android:layout_alignParentRight="true" 
     android:id="@android:id/selectedIcon" 
     android:src="???"> </ImageView> --> 

</TwoLineListItem> 

它除了箭頭圖標的所有作品:我無法找到該系統用於其適當的資源。

這是怎麼解決的?

或者我應該使用另一個控件而不是TwoLineListItem?

或者甚至試圖實現我作爲PreferencesActivity活動(以爲我需要我的活動有一定的EditText控件)?

對於參考,我需要的是左圖: http://androinica-serve.s3.amazonaws.com/wp-content/uploads/2010/11/evernote_comp2.png

回答

0

使用此佈局,並根據您的需要修改......

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF"> 

    <LinearLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_alignParentLeft="true"> 

    <TextView android:layout_width="fill_parent" 
     android:text="ggggggggg" 
     android:layout_height="wrap_content" android:id="@android:id/text1" 

     /> 
    <TextView android:layout_below="@android:id/text1" 
     android:text="ssssssssssss" 
     android:layout_height="wrap_content" 
     android:id="@android:id/text2" 
     android:layout_width="wrap_content" /> 
    </LinearLayout> 

    <ImageView android:layout_width="wrap_content" 
       android:layout_alignParentRight="true" 
       android:id="@android:id/selectedIcon" 
      android:layout_height="wrap_content" 
      android:src="@drawable/icon" 
      /> 

</RelativeLayout> 
+0

謝謝!但這並不能解決向下箭頭圖標的問題。我想重複使用一個系統(因爲它在模擬器和我的HTC設備上有所不同,所以在我的應用程序中聲明一個並不好)。可能嗎? – Forsaken 2011-05-24 14:21:23

0

您可以嘗試使用@android:繪製/ btn_dropdown獲取系統資源並將其設置爲背景。

2

哇,這個問題是如此古老,我不能相信沒有人回答正確大聲笑。你要找的佈局在SDK樹下:

[android-sdk-root]/platforms/[your-platform]/data/res/layout/preference.xml

,你會發現這個和這個文件夾中的任何其他SDK中定義的佈局。在res文件夾中釣魚,看看有什麼可用的。對不起,這是一年遲到了,但你有去。