我有一个ListView
,SherlockFragment
它滚动得很好。不确定是什么问题?也许您只是在某处有不正确的地方(可能想发布您的代码?)。下面是我的 ListView 和 XML:
MyFragment.java:
// Find the ListView we're using
list = (ListView)view.findViewById(R.id.listView);
// Set the vertical edges to fade when scrolling
list.setVerticalFadingEdgeEnabled(true);
// Create a new adapter
adapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.title, questions);
// Set the adapter to the list
list.setAdapter(adapter);
// Set on item click listener to the ListView
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// Do stuff
}
});
所有这些代码都是我在 Fragment 中与我的 ListView 相关的,它在我的onCreateView()
. 下面是它的 XML。
列表项.xml:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/arrow"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/title"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title"
android:layout_alignParentBottom="true"
android:layout_below="@+id/title"
android:layout_marginTop="5dp"
android:padding="2dp"
android:text="@string/date"
android:textColor="#7F7F7F"
android:textSize="12sp" />
</RelativeLayout>
<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:contentDescription="@string/app_name"
android:src="@drawable/arrow_next" />
列表视图.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:paddingTop="-2dp" >
<ListView
android:id="@+id/listView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
如果您发布您的代码,我们就有更好的机会提供帮助:)