0
A
回答
0
1-延長ListView
類
public class CustomListView extends ListView {
public CustomListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context) {
super(context);
}
private Runnable afterLayoutRunnable;
public void setAfterLayoutRunnable(Runnable afterLayoutRunnable) {
this.afterLayoutRunnable = afterLayoutRunnable;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (afterLayoutRunnable != null) {
afterLayoutRunnable.run();
}
}
}
2 - 創建自己的ArrayAdapter
public class CustomListAdapter extends ArrayAdapter<MyObject> {
public CustomListAdapter(Context context, int textViewResourceId, List<MyObject> objects) {
super(context, textViewResourceId, objects);
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.my_item_layout, null);
int height = TestActivity.listItemsMinimumHieght;
if (height > 0) {
convertView.setMinimumHeight(height);
}
}
}
}
3-在Activity
public class TestActivity extends Activity {
public static int listItemsMinimumHieght = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final CustomListView customListView = (CustomListView) findViewById(R.id.conversation_activity_button_send);
customListView.setAfterLayoutRunnable(new Runnable() {
@Override
public void run() {
listItemsMinimumHieght = customListView.getHeight()/4;
ArrayList<MyObject> objects=getListContent();
customListView.setAdapter(new ListViewConversationAdapter(TestActivity.this, R.id.sample, objects));
}
});
}
}
我認爲這應該工作,運氣好的話
相關問題
- 1. 填充設備上的圖像的列表視圖
- 2. 如何填充與多個Firebase項目的列表視圖
- 3. Android:填充列表視圖行中的多個項目
- 4. 設置焦點在Android的任何項目的列表視圖
- 5. 如何使用在另一個項目中填充的列表
- 6. Obj-c OS X:在表視圖中填充項目
- 7. 根據另一個列表項目填充列表項目
- 8. 值不填充在列表視圖
- 9. 填充列表視圖
- 10. 填充列表視圖
- 11. 如何在列表視圖項目上設置焦點?
- 12. Magento在移動設備上的目錄列表視圖
- 13. 在項目列表視圖
- 14. Android:填充列表視圖與數組項目
- 15. 填充列表視圖與自定義佈局項目
- 16. 當選擇列表視圖項目時填充文本框
- 17. 使用sql數據庫項目填充列表視圖
- 18. 填充樹視圖使用項目列表
- 19. Android將項目從SQLite填充到列表視圖
- 20. 使用光標填充項目到列表視圖後
- 21. 列表視圖的幾張圖片在滾動時填充所有listview項目
- 22. 填充列表視圖與一個ArrayList
- 23. 在Android中使用輸入xml中的子列表項填充列表視圖
- 24. 從項目列表中填充DataGrid
- 25. 在平板設備上填充
- 26. 在Access中填充項目
- 27. 在列表視圖中填充組合框列表
- 28. 如何使列表項在列表視圖的填充後可見?
- 29. 如何在主要方法外填充列表中的項目?
- 30. 如何在Primefaces選項列表中預先填充目標?
if'listItemsMinimumHieght = customListView.getHeight()/ 4;'沒有返回準確的高度,使用'listItemsMinimumHieght = customListView.getMeasuredHeight()/ 4;' –
謝謝!我會試試這個! – Filipe
它工作好嗎? –