我有RelativeLayout
及以下,我有一个ListView
。我必须将它们放在ScrollView
内。任何帮助都将深表感谢。
答案 0 :(得分:2)
你不应该把一个ListView放在ScrollView中,因为ListView类实现了自己的滚动,它只是不接收手势,因为它们都由父ScrollView处理
答案 1 :(得分:0)
ScrollView
只能为单个Layout
设置。因此,将您想要滚动的widgets
放在单个layout
中,如下所示:
<ScrollView
android:id="@+id/scrView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="@+id/rltvLyt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/lstView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
</RelativeLayout>
</ScrollView>
答案 2 :(得分:0)
答案 3 :(得分:0)
您不应该将ListView放在ScrollView中,因为ListView类实现了自己的滚动,它只是不接收手势,因为它们都由父ScrollView处理。我强烈建议你以某种方式简化你的布局。例如,您可以将要滚动的视图添加到ListView作为页眉或页脚。
private void setListViewScrollable(final ListView list) {
list.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
listViewTouchAction = event.getAction();
if (listViewTouchAction == MotionEvent.ACTION_MOVE)
{
list.scrollBy(0, 1);
}
return false;
}
});
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view,
int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE)
{
list.scrollBy(0, -1);
}
}
});
}
listViewTouchAction是一个全局整数值。如果你可以替换
行 list.scrollBy(0, 1);