当前位置: 首页>>代码示例>>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;未经允许,请勿转载。