Den*_*sGL 20 android android-layout
我尝试使用不同的列表项布局,具体取决于操作系统版本.
因此,我创建了与条件相关的不同布局.其中一个是(in layout/search_result_list_item.xml)
<?xml version="1.0" encoding="utf-8"?>
<include xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@android:layout/simple_list_item_1">
</include>
Run Code Online (Sandbox Code Playgroud)
它包括标准的"simple_list_item_1".
在我的Java代码中,布局与列表相关联,如下所示:
adapter = new SimpleCursorAdapter(getActivity(),
R.layout.search_results_list_item,
null,
from,
to,
0);
Run Code Online (Sandbox Code Playgroud)
显示列表项时,将引发以下异常:
android.view.InflateException: Binary XML file line #2: Error inflating class include
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.support.v4.widget.ResourceCursorAdapter.newView(ResourceCursorAdapt
Run Code Online (Sandbox Code Playgroud)
怎么了 ?不能用作根项目?尽管ADT允许它.
Tak*_*ion 31
如果有人想知道这是答案:
<?xml version="1.0" encoding="utf-8"?>
<merge>
<include xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@android:layout/simple_list_item_1">
</include>
</merge>
Run Code Online (Sandbox Code Playgroud)
您可以使用资源文件夹上的限定符提供 Android 操作系统版本特定的资源。
请参阅:http ://developer.android.com/guide/topics/resources/providing-resources.html
可能的限定符列表中的最后一项是版本(API 级别)。
| 归档时间: |
|
| 查看次数: |
3574 次 |
| 最近记录: |