In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "Android Development how to achieve the nesting of two ListView in ScrollView", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Android development how to achieve the nesting of two ListView in ScrollView" article.
The details are as follows:
In the project, you need to use two ListView to display on the same page. Because the data source is different, you can't distinguish the display by setting the flag bit in Adapter. In the end, you can only do a ScrollView to nest two ListView, but under normal circumstances, it cannot be displayed at the same time. The above ListView will be fully displayed, and the lower one only shows an Item. After looking up some information, you have finally succeeded.
There is mainly a ListViewUtility with the following code:
Import java.io.File;import android.content.Intent;import android.net.Uri;import android.view.View;import android.view.ViewGroup;import android.widget.ListAdapter;import android.widget.ListView;public class ListViewUtility {/ / is the display layout public static void setListViewHeightBasedOnChildren (ListView listView) {ListAdapter listAdapter = listView.getAdapter (); if (listAdapter = = null) {/ / pre-condition return;} int totalHeight = 0 added to a Scrollview. For (int I = 0; I < listAdapter.getCount ()) {/ / Global.pos = 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);}}
Then write two more Listview, as follows
SignListview.setAdapter (mYinggaoSignListAdapter); appListView.setAdapter (adapter); ListViewUtility.setListViewHeightBasedOnChildren (signListview); ListViewUtility.setListViewHeightBasedOnChildren (appListView)
Finally, add two ListView to the ListViewUtility, and the two ListView should be filled and then added. The outermost layer of the layout of the adpter in the two ListView should use LinearLayout. Only the LinearLayout in the ListViewUtility can successfully measure the height of each Item, otherwise there will be an error.
The above is about the content of this article on "how to achieve the nesting of two ListView in Android development ScrollView". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.