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

我已经开始学习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); 

我不明白这个代码特别是这一行:

 android.R.layout.simple_list_item_1 

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

以下是可以使用的布局的更多列表: http : //developer.android.com/reference/android/R.layout.html
(更新链接感谢@Estel: https : //github.com/android/platform_frameworks_base/tree/master/core/res/res/layout )

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

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

simple_list_item_1pipe理:

 <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:

 <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> 

如上所述:kcoppock和Joril

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

只需右键点击你想要的布局文件,然后select“另存为”,保存在某个地方,然后将其复制到android项目(eclipse)中的“布局”文件夹中。

你可以看到如何布局看起来像:)

走的路

正如Klap所提到的,“android.R.layout.simple_list_item_1是对作为Android OS的一部分的内置XML布局文档的引用”
所有布局位于:sdk \ platforms \ android-xx \ data \ res \ layout
要查看布局的XML:
Eclipse :只需在代码的某处键入android.R.layout.simple_list_item_1,按住Ctrl键,将鼠标hover在simple_list_item_1上,然后从出现的下拉列表中select“在layout / simple_list_item_1.xml中打开声明”。 它会引导你到XML的内容。
Android Studio :项目窗口 – >外部库 – > Android X平台 – > res – >布局,在这里您将看到可用布局的列表。
在这里输入图像描述

android.R.layout.simple_list_item_1 ,这是res / layout文件夹中的行布局文件,其中包含您在listview的行的相应devise。 现在我们通过使用mylistview.setadapter(aa)将数组列表项绑定到行布局。

没有必要去外部链接,你需要的一切都已经在你的计算机上:

Android的\ Android的SDK \平台\ Android的-X \ DATA \水库\布局。

所有的android布局的源代码位于这里。

Per Arvand:
Eclipse:只需在代码的某个地方键入android.R.layout.simple_list_item_1 ,按住Ctrl键,将鼠标hover在simple_list_item_1上 ,然后从出现的下拉列表中selectOpen / layout / simple_list_item_1.xml中的Open declaration 。 它会引导你到XML的内容。

从那里,如果你把鼠标hover在编辑器的simple_list_item_1.xml标签上,你会看到文件位于C:\ Data \ applications \ Android \ android-sdk \ platforms \ android-19 \ data \ res \ layout \ simple_list_item_1.xml (或您的安装的同等位置)。