Android:如何制作与首选项相似的列表视图?
我不想使用框架提供的首选项,而是希望创建一个类似的ListView。特别是,我希望它在文本视图中使用相同的字体大小和样式。尝试将此属性添加到您的Android:如何制作与首选项相似的列表视图?,android,Android,我不想使用框架提供的首选项,而是希望创建一个类似的ListView。特别是,我希望它在文本视图中使用相同的字体大小和样式。尝试将此属性添加到您的AndroidManifest.xml中的活动标记中 android:theme="@android:style/Preference.PreferenceScreen" 这与ListView本身无关,而是与出现在ListView中的子视图有关。它们是由适配器的getView方法创建的 要创建类似于Android的视图,可以使用Android源代码,
AndroidManifest.xml中的活动标记中
android:theme="@android:style/Preference.PreferenceScreen"
这与ListView本身无关,而是与出现在ListView中的子视图有关。它们是由适配器的getView方法创建的
要创建类似于Android的视图,可以使用Android源代码,特别是相关的XML文件布局。例如,preference.xml如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="4" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
您将无法直接使用此内容,因为使用的某些常量是Android专有的,您必须进一步深入挖掘其他xml
无论如何,你应该考虑到Android偏好在不同版本的Android和不同主题上看起来是不同的,所以确保你使用Android提供的常量,而不是你自己的硬编码值,确保列表视图项与Android提供的实际首选项相似。这完全取决于您所谈论的框架。每个供应商都有特定的调整,以区别于其他供应商。您可以随时从fw中获取Settings.apk,使用apk manager对其进行反编译,然后深入到那里的xmls中了解情况。谢谢,这正是我要查找的内容。Android源代码中的此文件(preference.xml)和相关首选项布局文件在哪里?编辑:我回答自己,最好在SDK文件夹中搜索:\SDK\platforms\android-19\data\res\layout
(文件以“首选项”开头)。