什么是“android.R.layout.simple_list_item_1”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3663745/
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-08-20 11:14:08  来源:igfitidea点击:

What is "android.R.layout.simple_list_item_1"?

androidlayoutandroid-arrayadapter

提问by Zakaria

I've started learning Android development and am following a todolist example from a book:

我已经开始学习 Android 开发,并且正在学习一本书中的 todolist 示例:

// Create the array list of to do items
final ArrayList<String> todoItems = new ArrayList<String>();

// Create the array adapter to bind the array to the listView
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(  this, 
                                android.R.layout.simple_list_item_1,
                                todoItems
                            );
myListView.setAdapter(aa);

I can't understand exactly this code especially this line:

我无法完全理解这段代码,尤其是这一行:

android.R.layout.simple_list_item_1

回答by Kevin Coppock

Zakaria, that is a reference to an built-in XML layout document that is part of the Android OS, rather than one of your own XML layouts.

Zakaria,这是对作为 Android 操作系统一部分的内置 XML 布局文档的引用,而不是您自己的 XML 布局之一。

Here is a further list of layouts that you can use: http://developer.android.com/reference/android/R.layout.html
(Updated link thanks @Estel: https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout)

这是您可以使用的布局的进一步列表:http: //developer.android.com/reference/android/R.layout.html
(更新链接感谢@Estel:https: //github.com/android/platform_frameworks_base/树/主/核心/资源/资源/布局

You can actually view the code for the layouts.

您实际上可以查看布局的代码。

回答by nikoo28

This is a part of the android OS. Here is the actual version of the defined XML file.

这是安卓操作系统的一部分。这是定义的 XML 文件的实际版本。

simple_list_item_1:

simple_list_item_1:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/listItemFirstLineStyle"
    android:paddingTop="2dip"
    android:paddingBottom="3dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

simple_list_item_2:

simple_list_item_2:

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="2dip"
    android:paddingBottom="2dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@android:id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/listItemFirstLineStyle"/>

    <TextView android:id="@android:id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/text1"
        style="?android:attr/listItemSecondLineStyle" />

</TwoLineListItem> 

回答by Nigel Crasto

as answered above by: kcoppock and Joril

如上回答:kcoppock 和 Joril

go here : https://github.com/android/platform_frameworks_base/tree/master/core/res/res/layout

去这里:https: //github.com/android/platform_frameworks_base/tree/master/core/res/res/layout

just right click the layout file you want, then select 'Save As', save somewhere, then copy it in 'layout' folder in your android project(eclipse)...

只需右键单击您想要的布局文件,然后选择“另存为”,保存在某处,然后将其复制到您的 android 项目(eclipse)中的“布局”文件夹中...

you can see how the layout looks like :)

你可以看到布局的样子:)

way to go...

要走的路...

回答by Arvand

As mentioned by Klap "android.R.layout.simple_list_item_1 is a reference to an built-in XML layout document that is part of the Android OS"
All the layouts are located in: sdk\platforms\android-xx\data\res\layout
To view the XML of layout :
Eclipse: Simply type android.R.layout.simple_list_item_1 somewhere in code, hold Ctrl, hover over simple_list_item_1, and from the dropdown that appears select "Open declaration in layout/simple_list_item_1.xml". It'll direct you to the contents of the XML.
Android Studio: Project Window -> External Libraries -> Android X Platform -> res -> layout, and here you will see a list of available layouts.
enter image description here

正如 Klap 提到的“android.R.layout.simple_list_item_1 是对作为 Android 操作系统一部分的内置 XML 布局文档的引用”
所有布局位于:sdk\platforms\android-xx\data\res\ layout
要查看布局的 XML:
Eclipse:只需在代码中的某处键入 android.R.layout.simple_list_item_1,按住 Ctrl,将鼠标悬停在 simple_list_item_1 上,然后从出现的下拉列表中选择“在布局/simple_list_item_1.xml 中打开声明”。它将引导您访问 XML 的内容。
Android Studio: Project Window -> External Libraries -> Android X Platform -> res -> layout,在这里你会看到可用布局的列表。
在此处输入图片说明

回答by Swathieswari

android.R.layout.simple_list_item_1, this is row layout file in your res/layout folder which contains the corresponding design for your row in listview. Now we just bind the array list items to the row layout by using mylistview.setadapter(aa);

android.R.layout.simple_list_item_1,这是 res/layout 文件夹中的行布局文件,其中包含listview. 现在我们只需使用以下命令将数组列表项绑定到行布局mylistview.setadapter(aa)

回答by Aaron Klap

No need to go to external links, everything you need is located on your computer already:

无需访问外部链接,您需要的一切都已在您的计算机上:

Android\android-sdk\platforms\android-x\data\res\layout.

Android\android-sdk\platforms\android-x\data\res\layout。

Source code for all android layouts are located here.

所有 android 布局的源代码都位于此处。

回答by Barry Holroyd

Per Arvand:
Eclipse: Simply type android.R.layout.simple_list_item_1somewhere in code, hold Ctrl, hover over simple_list_item_1, and from the dropdown that appears select Open declaration in layout/simple_list_item_1.xml. It'll direct you to the contents of the XML.

Per Arvand:
Eclipse:只需在代码中的某处键入android.R.layout.simple_list_item_1,按住 Ctrl,将鼠标悬停在simple_list_item_1 上,然后从出现的下拉列表中选择Open Declaration in layout/simple_list_item_1.xml。它将引导您访问 XML 的内容。

From there, if you then hover over the resulting simple_list_item_1.xmltab in the Editor, you'll see the file is located at C:\Data\applications\Android\android-sdk\platforms\android-19\data\res\layout\simple_list_item_1.xml(or equivalent location for your installation).

从那里,如果您将鼠标悬停在编辑器中生成的simple_list_item_1.xml选项卡上,您将看到该文件位于C:\Data\applications\Android\android-sdk\platforms\android-19\data\res\ layout\simple_list_item_1.xml(或安装的等效位置)。