问题
I'm trying to have some text and some buttons that appears right beneath the listview (which has a custom adapter) in my activity. If the number of things in the list gets too big then it should sit on the bottom of the screen while the list view scrolls on top.
Someone suggested I make a view out of it and put it as a footer but when I do it just treats the footer as a line in the listview and it scrolls with everything else. Here is my code
View footer = getLayoutInflater().inflate(R.layout.transaction_detail_footer, null);
TextView t=(TextView)footer.findViewById(R.id.total);
t.setText("Total: 558");
t= (TextView) footer.findViewById(R.id.funds);
t.setText("Funds: 9800");
getListView().addFooterView(footer);
setListAdapter(new TransactionAdapter(TestLV.this,Vs,Vs));
Where Vs is a string array.
Does anyone know how to get it to work?
回答1:
That's normal behavior for a ListView
. addFooterView()
adds the view to the end of the list, not the bottom of the screen. (See documentation). To achieve what you hope to see, you'll need to place another fixed View below the ListView
-- for example, a LinearLayout
containing the ListView
at the top and another LinearLayout
at the bottom.
来源:https://stackoverflow.com/questions/18450958/android-how-do-i-get-a-listview-to-stop-treating-a-footer-as-an-element-in-the