2012-09-07 48 views
2

我有一个滚动视图内的Listview并手动绑定其后面的代码的数据。我的主要问题是,当我绑定我的数据时,我的listview没有扩大其高度。我试过将其设置为wrap_content,fill_parent,但没有任何效果。这里是我的XMLScrollView里面的ListView也是滚动视图内

<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好友列表此列表视图中,它应该是滚动

+1

你不应该把一个ListView放在一个ScrollView中,因为ListView类实现了自己的滚动,它只是不接收手势,因为它们都是由父ScrollView处理的。我强烈建议你以某种方式简化你的布局。例如,您可以将要滚动到ListView的视图添加为页眉或页脚。 – VendettaDroid

+0

任何特定的原因,为什么你在ScrollView中包装ListView? –

+0

@Marek Sebera我包装listview的主要原因仅仅是因为我想关注我的Listview – Androyd

回答

1

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

使用ListView使其不滚动是非常昂贵的,并且针对ListView的整个目的而去 。你不应该这样做。只需要 就可以使用LinearLayout。

+0

但是,为什么我在scrollview中添加listview的主要目的是因为我想在布局上有两个滚动条。我需要它,因为我会把我的朋友列表放在该列表视图上。请看我上面的更新代码 – Androyd

+0

为什么不使用ExpandableListView呢? – sandrstar

+0

先生,我正在考虑创建一个xml,其中我将放置listview并使用填充父项并在我的scrollview中调用它。是否有可能? – Androyd

0

@Androyd朋友如果妳不把里面的ListView滚动视图,也没有内部的ListView滚动型的总是更好, ABD然后进行填充的ListView父母或修复DPS一些hieght像300dp或那么多高度ü希望...

相关问题