我有我的活动。它在android 4.2上完美运行,但是当我在2.3(模拟器和真实设备)上运行它时,我看到一个白色的屏幕(只在底部我看到“下一个”项目的一些像素)并且它都出现在我开始滚动。
清单:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/category_browser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:dividerHeight="1dp"
tools:listitem="@layout/category_browser_list_item" >
</ListView>
项目:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/category_browser_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:background="#ffffff"
android:clickable="true"
android:gravity="fill"
android:orientation="horizontal" >
<ImageView
android:id="@+id/category_browser_list_icon"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="fill"
android:layout_weight="0"
android:background="#ffffff"
android:contentDescription="@+id/category_browser_list_item_description"
android:src="@drawable/icon" />
<TextView
android:id="@+id/category_browser_list_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|start"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/category_browser_title"
android:textColor="#000000"
android:textSize="24sp" />
<CheckBox
android:id="@+id/category_browser_list_checkbox"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:clickable="false" />
</LinearLayout>
代码:
protected LinearLayout getListElementView() {
View listItem = inflator.inflate(R.layout.category_browser_list_item, null);
LinearLayout listElement = (LinearLayout)listItem.findViewById(R.id.category_browser_list_item);
return listElement;
}
public class CategoryListAdapter extends BaseAdapter {
@Override
public int getCount() {
int count = null != categories && null != categories.categories ? categories.categories.size() : 0;
Log.d(TAG, "getCount:" + count);
return count;
}
@Override
public Category getItem(int position) {
return null != categories && null != categories.categories ? categories.categories.get(position) : null;
}
@Override
public long getItemId(int position) {
return position;
}
// create a new ImageView for each item referenced by the Adapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout listView = null;
if (convertView != null) { // if it's not recycled, initialize some attributes
listView = (LinearLayout)convertView;
}
if (listView == null) { // if it's not recycled, initialize some attributes
listView = getListElementView();
}
final Category category = getItem(position);
category.setListView(listView);
File cacheIconFile = category.getCacheIconFile();
ImageView imageView = (ImageView)listView.findViewById(R.id.category_browser_list_icon);
if (cacheIconFile.exists()) {
imageView.setImageURI(Uri.fromFile(cacheIconFile));
} else {
Drawable noIcon = getResources().getDrawable(R.drawable.icon);
imageView.setImageDrawable(noIcon);
}
// Log.i(TAG, category.name + ": " + category.iconUrl + ": " + category.downloadBaseUrl);
if (null != category.name) {
TextView textView = (TextView)listView.findViewById(R.id.category_browser_list_title);
textView.setText(category.name);
}
listView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//start downloading category with downloadmanager
//(category);
Intent intent = category.getIntent();
if (null != intent)
startActivity(intent);
else {
category.setStatus(Category.CategoryDownloadStatus.DOWNLOADING);
downloadLocalePackage(category);
}
}
});
return listView;
}
}
答案 0 :(得分:0)
从android:clipChildren="false"
XML声明中删除ListView
。虽然您看到的效果可能是2.2 / 2.3中的错误,但在以后的版本中已经解决了这个问题,但这个属性在ListView
中确实没什么用处。