List View inside a Scroll View

二次信任 提交于 2019-12-25 12:33:24

问题


I have to implement the screen below. It looks perfectly fine on a 480*800 pixel screen. On a low resolution screen because of the lack of screen size the Scrolling of the Results exposes very small real estate for the user to scroll thru the results.

Which is the best way to implement it ?


回答1:


I always find trying to put something that scrolls into something else that scrolls is a nightmare so I would probably put the top of your view (results Bangalore to Mysore Date) inside the ListView header,that way it will scroll off the screen

listView.addHeaderView(listViewHeader);



回答2:


They are right. You shouldn't place listview into scrollview. Instead of it try this:

 <ScrollView android:layout_width="fill_parent" android:scrollbars="vertical"  
android:layout_height="wrap_content" android:scrollbarStyle="insideOverlay">  
<LinearLayout 
android:id="@+id/itemContainer"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="wrap_content"  
>     
<!-- YOUR ELEMENTS WILL BE PLACED HERE -->
 </LinearLayout>
</ScrollView>

Then you can add items from code:

private LinearLayout container; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);                
    setContentView(R.layout.YOUR_XML);  
    container = (LinearLayout)findViewById(R.id.itemContainer);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( 
             LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
/*CREATE YOUR ITEM*/
/*AND PLACE IT INTO CONTAINER*/
container.addView(YOUR_ITEM, layoutParams);
} 



回答3:


Put the portion you've shown in red border in a ListView which has Custom List Items. You don't really need a scrollview I guess. Just set the sort and filter buttons to parent bottom. And The listview between the buttons and the part above the list items. Best of luck.




回答4:


I tried using ListView inside ScrollView by using my own code available as answer at below link. Its working fine for me. Check it once and try it if you feel its good.

How to use listview inside scroll view




回答5:


You can put a ListView inside a ScrollView. Just extend the ListView to override the onTouchEvent method. Like so

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class ChildScrollView extends android.widget.ListView {
    private int parent_id;

    public ChildListView(Context context) {
        super(context);
    }

    public ChildListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ChildListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(event);
    }
}



回答6:


In this link, I write my solution to put a scrollable listview inside of a scrollview. I think that it can help you, if I understood your question

ListView inside scroll view magic



来源:https://stackoverflow.com/questions/9804230/list-view-inside-a-scroll-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!