java Android:包含标题和副标题的列表项的默认布局

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15390609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 19:25:48  来源:igfitidea点击:

Android: Default layout for listitem containing title and subtitle

javaandroidandroid-layoutandroid-listviewlistitem

提问by Xander

I have made a listitem, containing a title and a subtitle. Looking to the result, I think it doesn't look really professional. So that's why I'm asking.

我做了一个列表项,包含一个标题和一个副标题。从结果来看,我认为它看起来并不专业。所以这就是我问的原因。

The listitem I'm looking for is pretty common (it's used in a lot of apps i.e. Android's default settings menu and it's also shown when you add a listview in the graphical layout editor tab in eclipse).

我正在寻找的列表项非常常见(它在很多应用程序中使用,即 Android 的默认设置菜单,并且在 eclipse 的图形布局编辑器选项卡中添加列表视图时也会显示它)。

So my question is: Where can I find a default layout for a listitem with a title and a subtitle?

所以我的问题是:在哪里可以找到带有标题和副标题的列表项的默认布局?

回答by Mykhailo Gaidai

Resource id is android.R.layout.simple_list_item_2

资源 ID 是 android.R.layout.simple_list_item_2

Upper text line has id android.R.id.text1and lower one - android.R.id.text2

上面的文本行有 idandroid.R.id.text1和下面的一个 -android.R.id.text2

Layout is located in the <ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layoutfolder

布局位于<ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layout文件夹中

OR

或者

You can use TwoLineListItemfrom the default Android controls list(it is located under "Advanced" tab in Eclipse Layout Editor)

您可以使用TwoLineListItem默认的 Android 控件列表(它位于 Eclipse 布局编辑器中的“高级”选项卡下)

OR

或者

You can build your own layout with anything you like(for example LinearLayoutwith orientation="vertical"and two TextEdits added

您可以使用您喜欢的任何内容构建自己的布局(例如LinearLayout,添加了orientation="vertical"和 两个TextEdits

回答by Devam03

So The Best Way Is:- I took out the simple list item 2 and made an layout in my project and with little editing it took the same layout as you may give in android.R.simple_list_item_2

所以最好的方法是:- 我取出了简单的列表项 2 并在我的项目中做了一个布局,几乎没有编辑它就采用了与你在 android.R.simple_list_item_2 中给出的相同的布局

So the code is:-

所以代码是:-

   <?xml version="1.0" encoding="utf-8"?>

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">

<TextView android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:textAppearance="?attr/textAppearanceListItem" />

<TextView android:id="@id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/text1"
    android:layout_alignStart="@+id/text1"
    android:layout_alignLeft="@+id/text1"
    android:textAppearance="?attr/textAppearanceListItemSmall" />