我不想使用框架提供的首选项,而是我想创建一个看起来类似的ListView。特别是,我希望它为TextView使用相同的字体大小和样式。Android:如何制作一个类似于首选项的ListView?
6
A
回答
9
这不是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提供的实际偏好。
-1
1
添加这个属性的活动代码,请AndroidManifest.xml
android:theme="@android:style/Preference.PreferenceScreen"
+1
这给了我一个错误:'资源不是公开的' – Sam 2016-11-06 10:17:53
相关问题
- 1. 制作一个类似于android的应用程序,类似iphone
- 2. 如何制作一个类似Instagram的选项卡?
- 3. Android ListView:如何选择一个项目?
- 4. 一个类似于android的自定义childs的C#列表ListView
- 5. Android首选项如何去
- 6. 如何制作一个类似于Facebook的标题?
- 7. Android - 首次显示ListView时,首选ListView项目有时会被选中
- 8. 如何使用Qt创建类似于VLC的首选项窗口?
- 9. 如何从android的listview中选择一个特定的项目?
- 10. listview的每个项目的选项Android
- 11. android:如何查看我在ListView上选择的项目(多于一个)
- 12. 如何选择一个项目? - ListView
- 13. Android ==>首选项?
- 14. 如何创建一个类似于android中的gmail的协议?
- 15. Expandable ListView类似于Twitter
- 16. 如何创建一个类似IE9或Chrome的Dockable选项卡
- 17. 如何构建一个类似于此的Android应用程序
- 18. 如何创建一个类似于fb的事件表单android
- 19. 如何在Android中创建首选项?
- 20. 制作项目选择的ToggleButtons ListView
- 21. Android首选项,如何设置对自定义首选项的依赖
- 22. Android的首选项布局
- 23. Android:如何更改首选项中的选定项目颜色?
- 24. 如何专注于目前在Listview中选择的项目android
- 25. 共享首选项不工作,android?
- 26. Android共享首选项不起作用
- 27. 用于存储ListView数据的共享首选项
- 28. 制作一个类似于youtube.com的搜索栏
- 29. android,UTF8 - 如何确保UTF8用于共享首选项
- 30. 如何使用DatePickerDialog作为首选项
这完全取决于你在说什么框架。每个供应商都有特定的调整来区别于其他供应商。您可以随时从您的fw中获取Settings.apk,使用apk管理器反编译它,然后深入xml以获取想法。 – Aleadam 2011-04-13 21:58:06