ListView below scrollview in Android

后端 未结 5 926
予麋鹿
予麋鹿 2021-01-20 03:07

I am trying to put a ListView below a ScrollView in android. I tried putting them inside a LineaLayout like this



        
5条回答
  •  不要未来只要你来
    2021-01-20 03:40

    I would recommend you to put the ScrollView Content as HeaderView in the ListView or do you explicitly want to have two separated scrollable areas on screen?

    Example for putting the content of the scroll view in the list view as header (one single scrollable area):

    public void onCreate(Bundle s){
        setContentView(R.id.yourLayout);
    
        ListView listView = (ListView) findViewById(R.id.listView);
    
        // Set the adapter before the header, because older 
        // Android version may have problems if not
    
        listView.setAdapter(new YourAdapter());
    
        // Add the header
        View header = inflater.inflate(
                R.layout.you_layout_that_was_in_scrollview_before, null, false); 
    
        listView.addHeaderView(header);
    
    }
    

    The layout of the activity would look like that:

        
    
        
    
    

    If you want two scrollable areas, you should work with layout weight:

    
    
      
    
    
    
    

提交回复
热议问题