Android的:如何使一个ListView,类似于preferences? [英] Android: how to make a ListView that looks similar to Preferences?

查看:88
本文介绍了Android的:如何使一个ListView,类似于preferences?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望使用该框架提供preferences,而我想创建一个ListView看起来相似。特别是,我想它使用的TextViews相同的字体大小和样式。

I do not want to use the framework provided Preferences, rather I would like to create a ListView that looks similar. In particular, I would like it to use the same font size and style for the TextViews.

推荐答案

这是不是说在ListView内出现的ListView本身,而是孩子的意见。当您的适配器的getView方法创建的。

This is not about the ListView itself, but rather the child views that appear inside the ListView. They are created by the getView method of your adapter.

要创建到Android的观点类似,您可以使用Android源$ C ​​$ C,特别是相关的XML文件格式。例如,preference.xml看起来是这样的:

To create views similar to Android, you can use the Android source code, specifically the relevant XML file layouts. For example, preference.xml looks like this:

<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的进一步往下挖。

You will not be able to use this content directly, as some of the constants used are private to Android, and you'll have to further dig down through other xml's.

总之,你应该考虑到Android的preferences看看在不同的Andr​​oid版本的不同,在不同的主题,所以一定要使用由Android提供的常量,而不是你自己的硬件codeD值,以确保您的列表视图类似的项目由Android提供的实际preferences。

Anyhow, you should take into account that Android preferences look different on different versions of Android, and on different themes, so make sure you use the constants provided by Android, and not your own hard-coded values, to make sure your list-view items resemble the actual preferences provided by Android.

这篇关于Android的:如何使一个ListView,类似于preferences?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆