我在 Scrollview 中有一个 Listview,并在后面的代码中手动绑定了它的数据。我的主要问题是,当我绑定数据时,我的列表视图没有扩展它的高度。我尝试将其设置为wrap_content
,fill_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 中,它应该是可滚动的