Java ScrollView中的ListView,也在ScrollView中

Java ScrollView中的ListView,也在ScrollView中,java,android,Java,Android,我在Scrollview中有一个Listview,并将其数据手动绑定到后面的代码上。我的主要问题是,当我绑定数据时,我的listview没有扩展它的高度。我尝试将其设置为wrap\u content,fill\u parent,但没有任何效果。这是我的XML <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

我在Scrollview中有一个Listview,并将其数据手动绑定到后面的代码上。我的主要问题是,当我绑定数据时,我的listview没有扩展它的高度。我尝试将其设置为
wrap\u content
fill\u 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>

主要原因是我将把我的Facebook好友列表放在这个列表视图中,它应该是可滚动的。问题如下(如Romain Guy所述):

使用ListView使其不滚动是非常昂贵的,而且 与ListView的全部目的背道而驰。你不应该这样做。只是 改为使用线性布局


@Androyd Friend如果你不将listview放在scrollView中,也不将scrollView放在listview中,那就更好了,
abd然后使listview填充父对象,或在dps中修复一些高度,如300dp或您想要的高度…

您不应该将listview放在ScrollView中,因为listview类实现了自己的滚动,它只是不接收手势,因为它们都由父ScrollView处理。我强烈建议您以某种方式简化布局。例如,您可以添加要作为页眉或页脚滚动到ListView的视图,为什么要在ScrollView中包装ListView?@Marek Sebera我包装ListView的主要原因仅仅是因为我想专注于我的ListView,但是先生,我在ScrollView中添加ListView的主要目的是因为我想在布局上有两个滚动。我需要它,因为我会把我的朋友列表放在那个列表视图上。请看上面我的更新代码为什么不使用ExpandableListView?先生,我正在考虑创建一个xml,在其中我将放置listview并使用fill父级并在scrollview中调用它。这可能吗?在某种程度上类似。它可以让您拥有“分段”列表(并为不同的部分提供不同的数据)。你需要有一个适配器。
    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;
        }
    });