我的 ListView 非常简单,使用ViewHolder方法,但“橡胶”滚动不起作用。如果我用手指运行列表,它只是向下/向上 4-5 行并停止(所有列表大约有 50 行)。
适配器 getView 和 getHolder 方法
private ViewHolder getHolder(View vi) {
ViewHolder holder = new ViewHolder();
holder._id = (TextView) vi.findViewById(R.id._id);
holder.creator = (TextView) vi.findViewById(R.id.creator);
holder.message = (TextView) vi.findViewById(R.id.message);
holder.updated = (TextView) vi.findViewById(R.id.updated);
holder.userid = (TextView) vi.findViewById(R.id.userid);
return holder;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// return super.getView(position, convertView, parent);
ViewHolder holder;
View vi = convertView;
if (vi == null || vi.getTag() == null) {
vi = inflater.inflate(itemLayoutIdCommon, null);
holder = getHolder(vi);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
}
holder._id.setText((CharSequence) mValues.get(position).get("_id"));
holder.creator.setText((CharSequence) mValues.get(position).get("creator"));
holder.updated.setText((CharSequence) mValues.get(position).get("updated"));
holder.userid.setText((CharSequence) mValues.get(position).get("userid"));
holder.message.setText((CharSequence) mValues.get(position).get("title"));
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.message.getLayoutParams();
holder.message.setBackgroundResource(layoutChooser.getBackground(mValues.get(position)));
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
layoutParams.addRule(layoutChooser.getAlign(mValues.get(position))); // ALIGN_PARENT_RIGHT / LEFT etc.
holder.message.setLayoutParams(layoutParams);
return vi;
}
public static class ViewHolder {
TextView _id;
TextView userid;
TextView message;
TextView creator;
TextView updated;
}
和 row_layout.xml (itemLayoutIdCommon)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="_id"
android:visibility="gone" />
<TextView
android:id="@+id/userid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="userid"
android:visibility="gone" />
<TextView
android:id="@+id/creator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/updated"
android:tag="creator"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="14sp"
android:visibility="invisible" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="30dp"
android:enabled="false"
android:gravity="center_vertical|center_horizontal"
android:tag="title"
android:textColor="@color/black" >
</TextView>
<TextView
android:id="@+id/updated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:tag="updated"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/blue_border"
android:textSize="14sp" />
</RelativeLayout>
** lisview.xml **
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chat_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dim_foreground_disabled_holo_dark"
android:orientation="vertical" >
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/chat_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/tableRowMessage"
android:layout_alignParentLeft="true"
android:layout_below="@+id/actionBar1"
android:layout_gravity="fill"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:background="@drawable/chatshape"
android:dividerHeight="0dp"
android:fillViewport="true"
ptr:ptrAnimationStyle="flip"
android:cacheColorHint="#00000000"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:smoothScrollbar="true"
ptr:ptrMode="both" />
</RelativeLayout>