【发布时间】:2015-07-29 13:14:11
【问题描述】:
我正在 GitHub 上使用这个 AlhabetScroller
https://github.com/brightec/AlphabetScroller/blob/master/src/uk/co/brightec/alphabetscroller/AlphabetListAdapter.java
有文件list_alphabet.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fastScrollEnabled="true" />
<LinearLayout
android:id="@+id/sideIndex"
android:layout_width="40dip"
android:layout_height="fill_parent"
android:background="#FFF"
android:gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
我的问题与这一行有关:android:id="@android:id/list"
通常,我会这样做:android:id="@+id/my_list"
就像他对 sideIndex 所做的那样。相反,他使用的东西似乎使用了 Android 代码中已经存在的东西。
这样做的目的是什么?为什么这样做而不是我通常的做法?
编辑:
感谢拉利特·波塔尼。这个问题确实是重复的。
【问题讨论】:
-
如果您要扩展 ListActivity 或 ListFragment,那么您必须使用
android:id="@android:id/list"。否则,您可以随意使用任何您喜欢的名称(甚至在同一个 Activity 或 Fragment 中使用多个 ListView!)。这是一个非常古老的代码:我看到他们仍然使用fill_parent(在 API 级别 8 上已弃用)。而且.. 是的,我看到他们正在扩展 ListActivity:public class MainActivity extends ListActivity { -
感谢您的回复。我也注意到了
fill_parent。你知道这个功能的当代例子吗? -
从 API 级别 8 开始,使用
match_parent。 -
...类似this?
-
谢谢,我去看看。