gpt4 book ai didi

android - ListView requestLayout() 警告

转载 作者:太空狗 更新时间:2023-10-29 15:46:13 26 4
gpt4 key购买 nike

我有一个 ListView,它包含由 RelativeLayout 组成的项目:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.app.FragmentList">

<ListView
android:id="@+id/ListView01"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"
android:smoothScrollbar="false"
android:scrollingCache="true" />

</RelativeLayout>

项目:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="8dp"
android:paddingBottom="8dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Erika Mustermann"
android:id="@+id/textViewName"
android:layout_marginLeft="8dp"
android:layout_marginBottom="-3dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Company Inc."
android:id="@+id/textViewCompany"
android:layout_marginLeft="24dp"
android:textColor="#6b6b6b"
android:textSize="13dp"
android:visibility="gone" />

<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:id="@+id/linearLayout_one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Work: "
android:id="@+id/NumLabel0"
android:textColor="#6b6b6b" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+49-1234-1234567"
android:id="@+id/textViewPhoneWork"
android:textColor="#6b6b6b" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayout_two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_below="@+id/linearLayout_one">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Mobile: "
android:id="@+id/NumLabel1"
android:textColor="#6b6b6b" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+49-1234-1234567"
android:id="@+id/textViewPhoneMobile"
android:textColor="#6b6b6b" />
</LinearLayout>

</RelativeLayout>

</LinearLayout>

ListView 得到一个带有 ViewHolder 模式的 CursorAdapter,它的 bindView():

@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
holder.nameText.setText(cursor.getString(2) + ", " + cursor.getString(1));
Cursor values = getContactValues(cursor.getString(0));
values.moveToLast();
if (values.moveToFirst()) {
do {
if (values.getPosition() == 0) {
holder.type0Text.setText(replaceType(values.getString(0), context) + ": ");
holder.num0Text.setText(values.getString(1));
} else {
holder.type1Text.setText(replaceType(values.getString(0), context) + ": ");
holder.num1Text.setText(values.getString(1));
}
} while (values.getPosition() < 2 && values.moveToNext());

int pos = values.getPosition();
if (pos == 1) {
holder.type1Text.setVisibility(View.GONE);
holder.num1Text.setVisibility(View.GONE);
}
if (values.getPosition() == 2) {
holder.type1Text.setVisibility(View.VISIBLE);
holder.num1Text.setVisibility(View.VISIBLE);
}
}
values.close();

}

它的新 View :

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = View.inflate(context, R.layout.contact_item, null);
ViewHolder holder = new ViewHolder();
holder.nameText = (TextView) view.findViewById(R.id.textViewName);
holder.type0Text = (TextView) view.findViewById(R.id.NumLabel0);
holder.type1Text = (TextView) view.findViewById(R.id.NumLabel1);
holder.num0Text = (TextView) view.findViewById(R.id.textViewPhoneWork);
holder.num1Text = (TextView) view.findViewById(R.id.textViewPhoneMobile);
view.setTag(holder);
return view;
}

CursorAdapter 及其构造函数的创建:

cadapter = new ContactListCursorAdapter(view.getContext(), namesCursor, 0, readDB, arg2 + 1);

和:

ContactListCursorAdapter(Context context, Cursor c, int flags, SQLiteDatabase readDB, int _ID) {
super(context, c, flags);
this.readDB = readDB;
Cursor tmpc = readDB.query(SQLiteHelper.TABLE, new String[]{SQLiteHelper._ID}, SQLiteHelper.COLUMN_ID + "=?", new String[]{String.valueOf(_ID)}, null, null, null, null);
tmpc.moveToFirst();
this.list = tmpc.getString(tmpc.getColumnIndex(SQLiteHelper._ID));
}

每当显示或更新 View 时,我都会收到类型警告:

14:25:33.543  27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d97830 V.ED.... ......ID 24,24-364,105 #7f09003f app:id/textViewName} during layout: running second layout pass
14:25:33.543 27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d988b8 V.ED.... ......ID 0,0-165,52 #7f090043 app:id/NumLabel0} during layout: running second layout pass
14:25:33.543 27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d98ce0 V.ED.... ......ID 165,0-488,52 #7f090044 app:id/textViewPhoneWork} during layout: running second layout pass
14:25:33.543 27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d9b380 V.ED.... ......ID 24,24-467,105 #7f09003f app:id/textViewName} during layout: running second layout pass
14:25:33.543 27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d9c408 V.ED.... ......ID 0,0-165,52 #7f090043 app:id/NumLabel0} during layout: running second layout pass
14:25:33.543 27597-27597/com.app W/View﹕ requestLayout() improperly called by android.widget.TextView{41d9c830 V.ED.... ......ID 165,0-488,52 #7f090044 app:id/textViewPhoneWork} during layout: running second layout pass

我不知道这个错误发生在哪里......以及为什么。

似乎 com.android.contacts 也遇到了同样的问题。

06-16 15:12:10.113  27522-27522/com.android.contacts W/View﹕ requestLayout() improperly called by android.widget.TextView{41ed52f8 V.ED.... ......ID 216,90-936,149 #7f0c000e app:id/cliv_name_textview} during layout: running second layout pass

最佳答案

好吧,我知道这是一个旧线程,但如果其他人遇到同样的问题,那是由于 fastScrollEnabled 导致的。

要摆脱它只需删除

    android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"

希望对大家有帮助。

关于android - ListView requestLayout() 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24243932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com