當前位置: 首頁>>代碼示例>>Java>>正文


Java ListView.requestLayout方法代碼示例

本文整理匯總了Java中android.widget.ListView.requestLayout方法的典型用法代碼示例。如果您正苦於以下問題:Java ListView.requestLayout方法的具體用法?Java ListView.requestLayout怎麽用?Java ListView.requestLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.ListView的用法示例。


在下文中一共展示了ListView.requestLayout方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * Taken from Stack Overflow - https://stackoverflow.com/a/26501296
 * Updates the ListView height based on its children
 *
 * @param listView the ListView to adjust
 */

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
開發者ID:jthomperoo,項目名稱:Forge,代碼行數:28,代碼來源:GeneratorFragment.java

示例2: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); 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);
    listView.requestLayout();
}
 
開發者ID:Elbehiry,項目名稱:Viajes,代碼行數:20,代碼來源:Utils.java

示例3: setListViewHeight

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 動態設置ListView的高度,count大於6設置固定高度
 * 在Android4.4.4版本之前,手動計算View的高度,而View中含有RelativeLayout
 * 就會出現onMeasure時NullPointerException這種錯誤,
 * 解決辦法:
 * 一是調用measure方法前判斷一下版本,
 * 二是盡量不要使用RelativeLayout,使用LinearLayout或者FrameLayout等布局。
 * @param listView
 */
public static void setListViewHeight(ListView listView) {
    int totalHeight = 0;
    if (listView == null) {
        return;
    }
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight;
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
開發者ID:lpy19930103,項目名稱:MinimalismJotter,代碼行數:29,代碼來源:ScreenUtil.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
/**** Method for Setting the Height of the ListView dynamically.
 **** Hack to fix the issue of not showing all the items of the ListView
 **** when placed inside a ScrollView  ****/
private static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        return;

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, WindowManager.LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:25,代碼來源:AboutFragment.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * Shrink listview height
 * @param listView
 * @param adapter
 */
public void setListViewHeightBasedOnChildren(ListView listView, AboutAdapter adapter) {
    int totalHeight = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View listItem = adapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight() + 180;
        Log.i("htbridge", "listItem.getMeasuredHeight()  = " + listItem.getMeasuredHeight() );
    }

    Log.i("htbridge", "totalHeight = " + totalHeight);

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();

}
 
開發者ID:HTBridge,項目名稱:pivaa,代碼行數:23,代碼來源:AboutActivity.java

示例6: setListViewHeightBasedOnItems

import android.widget.ListView; //導入方法依賴的package包/類
public static boolean setListViewHeightBasedOnItems(ListView listView) {

        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter != null) {

            int numberOfItems = listAdapter.getCount();

            // Get total height of all items.
            int totalItemsHeight = 0;
            for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
                View item = listAdapter.getView(itemPos, null, listView);
                item.measure(0, 0);
                totalItemsHeight += item.getMeasuredHeight();
            }

            // Get total height of all item dividers.
            int totalDividersHeight = listView.getDividerHeight() *
                    (numberOfItems - 1);

            int topPAdding = listView.getPaddingTop();
            int bottomPadding = listView.getPaddingBottom();

            // Set list height.
            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalItemsHeight + totalDividersHeight + topPAdding + bottomPadding;
            listView.setLayoutParams(params);
            listView.requestLayout();

            return true;

        } else {
            return false;
        }

    }
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:36,代碼來源:ViewUtil.java

示例7: extendListView

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * Used when  we need to nest a ListView inside a ScrollView.
 * eg: ShowParentageFragment.
 * more info: https://stackoverflow.com/questions/27646209/disable-scrolling-for-listview-and-enable-for-whole-layout
 *
 * @param listView the listView that we want to extends
 */
public static void extendListView(ListView listView) {
  ListAdapter listAdapter = listView.getAdapter();

  if (listAdapter == null) return;

  int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
  int totalHeight = 0;
  View view = null;

  for (int i = 0; i < listAdapter.getCount(); i++) {
    view = listAdapter.getView(i, view, listView);

    if (i == 0) {
      view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
    totalHeight += view.getMeasuredHeight();
  }

  ViewGroup.LayoutParams params = listView.getLayoutParams();
  params.height = totalHeight + ((listView.getDividerHeight()) * (listAdapter.getCount()));

  listView.setLayoutParams(params);
  listView.requestLayout();

}
 
開發者ID:goutfeb,項目名稱:ElephantAsia,代碼行數:35,代碼來源:ViewHelpers.java

示例8: setHeightofListViewBasedOnContent

import android.widget.ListView; //導入方法依賴的package包/類
public void setHeightofListViewBasedOnContent(ListView listView) {

        ListAdapter mAdapter = listView.getAdapter();

        int totalHeight = 0;

        for (int i = 0; i < mAdapter.getCount(); i++) {

            totalHeight += getResources().getDimension(R.dimen.item_list_height);
            Log.w("HEIGHT" + i, String.valueOf(totalHeight));

        }

        totalHeight = totalHeight +  (listView.getDividerHeight() * (mAdapter.getCount() - 1)) + listView.getPaddingTop();

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight;
        listView.setLayoutParams(params);
        listView.requestLayout();

    }
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:22,代碼來源:ArtistDetailActivity.java


注:本文中的android.widget.ListView.requestLayout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。