2011-05-24 67 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文件夹中钓鱼,看看有什么可用的。对不起,这是一年迟到了,但你有去。