2

我在 Scrollview 中有一个 Listview,并在后面的代码中手动绑定了它的数据。我的主要问题是,当我绑定数据时,我的列表视图没有扩展它的高度。我尝试将其设置为wrap_contentfill_parent但没有任何效果。这是我的 XML

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parentScrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<RelativeLayout
>

<LinearLayout >

    <ImageView
        />

    <LinearLayout
         >

        <TextView />

        <TextView />

        <LinearLayout >

            <TextView/>

            <TextView/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView/>

            <TextView />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<View />

<TextView/>

<ScrollView
    android:id="@+id/childScrollView"
    android:layout_width="match_parent"
    android:layout_height="375dp"
    android:layout_below="@+id/view1"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_marginTop="18dp"
    android:background="@drawable/scrollviewborder"
    android:scrollbarStyle="insideInset" >

    <ListView
        android:id="@+id/listFriends"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="2dip"
        android:paddingLeft="2dip"
        android:paddingRight="2dip"
        android:paddingTop="2dip"
        >
    </ListView>


</ScrollView>

<Button />

</RelativeLayout>

</ScrollView>

请看它是一个嵌套的 ListView,这是我的代码

    ArrayList<HashMap<String, String>> friendList = new ArrayList<HashMap<String, String>>();
    // adding database values to HashMap key => value
    for (int i = 0; i < friendName.length; i++) {
        // creating new HashMap
        HashMap<String, String> friend = new HashMap<String, String>();
            //merchant.put(KEY_ID, merchantIdArray[i]); 
            friend.put(KEY_FRIEND_NAME, friendName[i]);
            friend.put(KEY_THUMB_URL,imageIDs[i]);
        friendList.add(friend);
    }

    list=(ListView)findViewById(R.id.listFriends);
     adapter =new LazyAdapter(this, friendList);        
     list.setAdapter(adapter);

似乎是什么问题?

编辑 我添加了这个代码来验证应该使用哪个滚动

    parentScrollView= (ScrollView) findViewById(R.id.parentScrollview);
    parentScrollView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
             //Log.v(TAG,"PARENT TOUCH");
             findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
            return false;
            }
        });
    childScrollView= (ScrollView) findViewById(R.id.childScrollView);
    childScrollView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
             //Log.v(TAG,"PARENT TOUCH");
             findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

这样做的主要原因是我将把我的 Facebook 好友列表放在这个 Listview 中,它应该是可滚动的

4

2 回答 2

1

问题如下(如Romain Guy 所述):

使用 ListView 使其不滚动非常昂贵,并且违背了 ListView 的全部目的。你不应该这样做。只需使用 LinearLayout 代替。

于 2012-09-07T06:32:00.953 回答
0

@Androyd朋友如果你不把listview放在scrollView里面,也不把scrollview放在listview里面,那么它总是更好,然后让listview填充父级或者修复dps中的一些高度,比如300dp或者你想要的高度......

于 2012-09-07T06:33:26.323 回答