2

2 つのリスト ビューがあります。

私が抱えている問題は、小さい(高さの)リストビューが一番下に達するまで画面がスクロールすることです。
長いリストビューの一番下までスクロールできるように、含まれているビューを展開するにはどうすればよいですか?

両方のリストを同時にスクロールするために onScroll をオーバーロードしました。

    public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

        super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
        if (view.getChildAt(0) != null) {
            if (view.equals(m_lv1) ){
                m_lv2.setSelectionFromTop(view.getFirstVisiblePosition(),
                    view.getChildAt(0).getTop());
            } else if (view.equals(m_lv2) ){
                m_lv1.setSelectionFromTop(view.getFirstVisiblePosition(),
                    view.getChildAt(0).getTop());
            }
        }
    }


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"  
    android:layout_height="match_parent">

  <ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scrollbars="none"  
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>
</LinearLayout>
4

2 に答える 2

2

リストビューの高さを設定する必要があります...のように。

<ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="120dp"
      android:scrollbars="none"  
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="120dp"
      android:layout_weight="1" >
  </ListView>
于 2012-11-28T07:13:52.337 に答える
1

コードの代わりに以下のXMLコードを使用してください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent">

  <ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>
</LinearLayout>
于 2012-11-28T07:22:13.557 に答える