2014-09-25 160 views
0

我有一个listview内滚动视图。这是我的xml文件列表视图不滚动滚动视图内

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#ffffff" > 

<ScrollView 
    android:id="@+id/scrollView2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/viewtop" 
    android:layout_marginBottom="10dp" 
    android:fadingEdgeLength="0dp" 
    android:fillViewport="true" 
    android:overScrollMode="never" 
    android:scrollbars="none" > 

    <RelativeLayout 
     android:id="@+id/rel111" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" > 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:padding="8dip" 
      android:text="@string/franchise" 
      android:textSize="25dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView3" 
      android:layout_marginLeft="33dp" 
      android:layout_marginTop="10dp" 
      android:padding="8dip" 
      android:text="@string/neworder" 
      android:textSize="20dp" /> 

     <TextView 
      android:id="@+id/textView77" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/ettesttube" 
      android:layout_below="@+id/input_order" 
      android:layout_marginTop="5dp" 
      android:text="Tube Count" 
      android:textSize="15dp" /> 

     <ImageButton 
      android:id="@+id/ibtdown" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_alignBottom="@+id/ettesttube" 
      android:layout_alignLeft="@+id/input_order" 
      android:layout_alignTop="@+id/ettesttube" 
      android:layout_below="@+id/textView77" 
      android:background="@drawable/down" /> 

     <EditText 
      android:id="@+id/ettesttube" 
      android:layout_width="80dp" 
      android:layout_height="40dp" 
      android:layout_below="@+id/textView77" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="3dp" 
      android:layout_toRightOf="@+id/ibtdown" 
      android:background="@drawable/squarecorner" 
      android:ems="10" 
      android:inputType="number" 
      android:text="1" > 
     </EditText> 

     <ImageButton 
      android:id="@+id/ibtup" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_alignBottom="@+id/ettesttube" 
      android:layout_alignTop="@+id/ettesttube" 
      android:layout_toRightOf="@+id/ettesttube" 
      android:background="@drawable/up" /> 


     <RelativeLayout 
      android:id="@+id/rellist" 
      android:layout_width="fill_parent" 
      android:layout_height="200dp" 
      android:layout_below="@+id/textView6" 
      android:layout_marginBottom="6dp" 
      android:layout_marginLeft="35dp" 
      android:layout_marginRight="40dp" 
      android:background="@drawable/roundcorner" > 

      <ListView 
       android:id="@+id/listView1" 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       android:layout_weight="1" 
       android:fadeScrollbars="false" 
       android:fastScrollEnabled="true" 
       android:longClickable="true" > 
      </ListView> 
     </RelativeLayout> 

     <Button 
      android:id="@+id/button_submit" 
      android:layout_width="80dp" 
      android:layout_height="35dp" 
      android:layout_alignLeft="@+id/rellist" 
      android:layout_below="@+id/rellist" 
      android:layout_marginTop="6dp" 
      android:background="@drawable/btn_bg" 
      android:text="Submit" /> 

     <Button 
      android:id="@+id/button_no_order" 
      android:layout_width="80dp" 
      android:layout_height="35dp" 
      android:layout_alignBottom="@+id/button_clear" 
      android:layout_alignTop="@+id/button_clear" 
      android:layout_below="@+id/rellist" 
      android:layout_gravity="center" 
      android:layout_toRightOf="@+id/button_clear" 
      android:background="@drawable/btn_bg" 
      android:text="No Order" /> 

     <View 
      android:id="@+id/blank" 
      android:layout_width="fill_parent" 
      android:layout_height="30dp" 
      android:layout_below="@+id/button_clear" /> 

     <ImageView 
      android:id="@+id/showImg" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="35dp" 
      android:src="@drawable/abc_ab_bottom_solid_dark_holo" 
      android:visibility="gone" /> 
    </RelativeLayout> 
</ScrollView> 
</RelativeLayout> 

问题是,列表视图不滚动

我尝试这样做:

public class Utility { 
public static void setListViewHeightBasedOnChildren(ListView listView) { 
    ListAdapter listAdapter = listView.getAdapter(); 
    if (listAdapter == null) { 
     // pre-condition 
     return; 
    } 

    int totalHeight = 0; 
    for (int i = 0; i < listAdapter.getCount(); i++) { 
     View listItem = listAdapter.getView(i, null, listView); 
     listItem.measure(0, 0); 
     totalHeight += listItem.getMeasuredHeight(); 
    } 

    ViewGroup.LayoutParams params = listView.getLayoutParams(); 
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
    listView.setLayoutParams(params); 
} 
}  

在活动课我写这个设置适配器后:

Utility.setListViewHeightBasedOnChildren(list); 

但仍列表不滚动。

谢谢!

+1

滚动视图下的listview从不起作用。 – 2014-09-25 09:48:15

+0

发布你的清单行xml – 2014-09-25 09:51:12

+0

ListView里面的ScrollView =滚动,滚动内的滚动。想想看,这并没有什么意义...... – 2Dee 2014-09-25 09:51:20

回答

1
ListView listView; 
listView.setOnTouchListener(new ListView.OnTouchListener() { 
@Override 
public boolean onTouch(View v, MotionEvent event) { 
if (event.getAction() == MotionEvent.ACTION_MOVE) 
{ 
listView.scrollBy(0, 1); 
} 
return false; 
} 
}); 

一次检查这个代码

ListView lv = (ListView)findViewById(R.id.myListView); 
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; 
    } 
}); 

如果你请接受的答案是有用的。

+0

感谢您的回答。但它不起作用。 – Saurabh 2014-09-25 09:57:20

+0

单独为列表视图设置滚动视图。 – iffu 2014-09-25 10:31:10