多行中的Textview文本,Scrollview中的Listview

时间:2014-08-26 17:27:37

标签: android

我在listview中使用scrollview。我可以使用以下方法在Scrollview中的listview中显示列表。

public static void setListViewHeightBasedOnChildren(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();
    if (myListAdapter == null) {
        // do nothing return null
        return;
    }
    // set listAdapter in loop for getting final size
    int totalHeight = 0;
    for (int size = 0; size < myListAdapter.getCount(); size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // setting listview item in adapter
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight
            + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
    myListView.setLayoutParams(params);
    // print height of adapter on log
    Log.i("height of listItem:", String.valueOf(totalHeight));
}

textview中有listview,而textview的文字太长,有3行或4行。在这种情况下,listview未显示所有项目。

0 个答案:

没有答案