2

スクロールせずにすべてのアイテムを表示するようにリストビューを設定したい。
以下は私のレイアウトです:

<LinearLayout
          android:id="@+id/layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" >

      <TextView
      android:id="@+id/tv1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Large Text"
      android:textColor="@android:color/black"
      android:textAppearance="?android:attr/textAppearanceLarge" />

      <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <TextView
         android:id="@+id/tv2"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Large Text"
         android:textColor="@android:color/black"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     </LinearLayout>

linearlayout は scrollview に属しています。
だから私はリストビューのすべてのアイテムを設定し、親のスクロールでスクロールしたい。
どうすればいいですか?

4

4 に答える 4

5

これはスクロールビューでリストビューを設定する方法ですが、他の誰かが答えたように、特にリストビューに多くのアイテムが含まれる場合は、リストビューをスクロールビューに配置しないでください

ListView lv = (ListView)findViewById(R.id.list);  // your listview inside scrollview

lv.setOnTouchListener(new ListView.OnTouchListener() 
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        int action = event.getAction();
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
            // Disallow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle ListView touch events.
        v.onTouchEvent(event);
        return true;
    }
});
于 2013-09-04T07:51:32.220 に答える
2

ありえないと思います。親レイアウトのスクロールを使用してリスト ビューのスクロール動作をオーバーライドすると、リスト ビューが正しく機能しませんでした。

于 2013-09-04T08:02:03.810 に答える