Listview disable internal scrolling on Android

自古美人都是妖i 提交于 2019-12-04 20:24:17

First of all, add a ScrollView as root item for your layout it will allow you to scroll between all the items in your layout (it will be necessary for the existing TableLayout on small screen phones).

Then replace the ListView by a vertical LinearLayout and inflate manually as much rows as you need with a similar method:

LinearLayout llContainer = (LinearLayout) findViewById(R.id.yourBottomLinearLayout);

LayoutInflater inflater = LayoutInflater.from(getApplicationContext());

for (Item item : mListItems){           
    LinearLayout llItem = (LinearLayout) inflater.inflate(R.layout.row, null);
    TextView vin = (TextView) llItem.findViewById(R.id.vin);
    vin.setText(item.getFirstText());
    TextView desc = (TextView) llItem.findViewById(R.id.desc);
    desc.setText(item.getSecondText());
    // To know wich item has been clicked
    llItem.setTag(item.getId());
    // In the onClickListener just get the id using getTag() on the view
    llItem.setOnClickListener(this);
    llContainer.addView(llItem);
}

Your ScrollView will increase size as much as needed and you will be able to scroll on the entire screen.

Other and better answer (it was late yesterday...)

You can use a simple ListView and add a header TableLayout:

Create a specific layout for the TableView.

In the onCreate method:

LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View headerView = inflater.(R.layout.header, mListView, false);
mListView.addHeaderView(headerView);

With this method you will have the header containing the table view automatically managed by the ListView and showed when the user scroll to the beginning of the ListView.

You keep the benefice of cell reuse from the standard adapter.

You could simply put all your rows in a linear layout. I assume you already have a row-layout defined. All you need to do is loop through you data and inflate one row for each item. A listview is suppost to scroll and uses a lot of tricks to consume less resources than displaying all items at once.

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