当前位置: 首页>>代码示例>>Java>>正文


Java ListView.getLayoutParams方法代码示例

本文整理汇总了Java中android.widget.ListView.getLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.getLayoutParams方法的具体用法?Java ListView.getLayoutParams怎么用?Java ListView.getLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.ListView的用法示例。


在下文中一共展示了ListView.getLayoutParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @Title: setListViewHeightBasedOnChildren @Description:
 * TODO(根据ListView算出List的高度) @param @param mContext @param @param
 * listView 参数 @return void 返回类型 @throws
 */
public static void setListViewHeightBasedOnChildren(Context mContext, ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        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);
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:22,代码来源:Utils.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);
}
 
开发者ID:littleRich,项目名称:AutoInteraction-Library,代码行数:19,代码来源:Util.java

示例3: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        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 = 80 * (listAdapter.getCount() - 1);
    // params.height = 80 * (listAdapter.getCount());
    params.height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    ((ViewGroup.MarginLayoutParams) params).setMargins(0, 0, 0, 0);
    listView.setLayoutParams(params);

}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:21,代码来源:ExpandedListUtils.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * 设置ListView全部显示的高度
 * @param listView 要设置的ListView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
       //获取ListView对应的Adapter
    ListAdapter listAdapter = listView.getAdapter(); 
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) {   //listAdapter.getCount()返回数据项的数目
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);  //计算子项View 的宽高
        totalHeight += listItem.getMeasuredHeight();  //统计所有子项的总高度
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    //listView.getDividerHeight()获取子项间分隔符占用的高度
    //params.height最后得到整个ListView完整显示需要的高度
    listView.setLayoutParams(params);
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:26,代码来源:MyUtils.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @author sunglasses
 * @param listView
 * @category 计算listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		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);
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:24,代码来源:Tools.java

示例6: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/***
 * 动态设置listview的高度
 * 
 * @param listView
 */
public void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		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));
	// params.height += 5;// if without this statement,the listview will be
	// a
	// little short
	// listView.getDividerHeight()获取子项间分隔符占用的高度
	// params.height最后得到整个ListView完整显示需要的高度
	listView.setLayoutParams(params);
}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:27,代码来源:EditSchoolActivity.java

示例7: onGlobalLayout

import android.widget.ListView; //导入方法依赖的package包/类
@Override
public void onGlobalLayout() {
    int barHeight = getActivity().getActionBar().getHeight();
    ListView listView = getListView();
    FrameLayout.LayoutParams params = (LayoutParams) listView.getLayoutParams();
    // The list view top-margin should always match the action bar height
    if (params.topMargin != barHeight) {
        params.topMargin = barHeight;
        listView.setLayoutParams(params);
    }
    // The action bar doesn't update its height when hidden, so make top-margin zero
    if (!getActivity().getActionBar().isShowing()) {
      params.topMargin = 0;
      listView.setLayoutParams(params);
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:TitlesFragment.java

示例8: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @param listView
 * @author sunglasses
 * @category 计算listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        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);
}
 
开发者ID:TAnsz,项目名称:MyTvLauncher,代码行数:24,代码来源:Tools.java

示例9: 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

示例10: SimpleTableAdapter

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @param data              数据
 * @param layoutResId       数据的布局的id
 * @param resIds            数据的布局的每个view的id
 * @param headers           header的数据
 * @param headerLayoutResId header的布局的id
 * @param headerResIds      header的布局的每个view的id
 * @param listView          用来更新listview高度
 * @param itemHeight        单个item的高度(单位dp)
 * @param activity
 */
public SimpleTableAdapter(@Nullable List data, int layoutResId, int[] resIds,
                          String[] headers, int headerLayoutResId, int[] headerResIds,
                          ListView listView, int itemHeight, Activity activity) {
    super(data, 2);
    data.add(0, Arrays.asList(headers));
    setData(data);
    this.headerLayoutResId = headerLayoutResId;
    this.layoutResId = layoutResId;
    this.resIds = resIds;
    this.headerResIds = headerResIds;
    int heightDp = itemHeight * data.size() + (int) (data.size() * 1.2);
    listView.getLayoutParams().height = new DensityUtils(activity).dip2px(heightDp);
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:25,代码来源:SimpleTableAdapter.java

示例11: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {
        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();
        }
        LayoutParams params = listView.getLayoutParams();
        params.height = (listView.getDividerHeight() * (listAdapter.getCount() - 1)) + totalHeight;
        listView.setLayoutParams(params);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:LetvUtil.java

示例12: 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

示例13: buildViews

import android.widget.ListView; //导入方法依赖的package包/类
private View buildViews() {
    View wrapperView = View.inflate(mContext, getContentViewLayoutId(), null);
    mTitleTv = (TextView) wrapperView.findViewById(R.id.title);
    mContainerView = (ListView) wrapperView.findViewById(R.id.listview);
    if (mTitle != null && mTitle.length() != 0) {
        mTitleTv.setVisibility(View.VISIBLE);
        mTitleTv.setText(mTitle);
    } else {
        mTitleTv.setVisibility(View.GONE);
    }
    if (mHeaderViews.size() > 0) {
        for (View headerView : mHeaderViews) {
            mContainerView.addHeaderView(headerView);
        }
    }
    if (needToScroll()) {
        mContainerView.getLayoutParams().height = getListMaxHeight();
        mDialog.setOnBottomSheetShowListener(new OnBottomSheetShowListener() {
            @Override
            public void onShow() {
                mContainerView.setSelection(mCheckedIndex);
            }
        });
    }

    mAdapter = new ListAdapter();
    mContainerView.setAdapter(mAdapter);
    return wrapperView;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:30,代码来源:QMUIBottomSheet.java

示例14: makeCenterView

import android.widget.ListView; //导入方法依赖的package包/类
@Override
@NonNull
protected LinearLayout makeCenterView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setOrientation(LinearLayout.VERTICAL);

    mListView = new ListView(activity);
    mListView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    mListView.getLayoutParams().height = screenHeightPixels/4;
    mListView.setPadding(30, 10, 30, 10);
    // 去掉分割线
    mListView.setDividerHeight(0);
    mListView.setAdapter(mWeekAdapter);
    rootLayout.addView(mListView);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
                                int arg2, long arg3) {
            // 取得ViewHolder对象,这样就省去了通过层层的findViewById去实例化我们需要的cb实例的步骤
            WeekAdapter.ViewHolder holder = (WeekAdapter.ViewHolder) arg1.getTag();
            // 改变CheckBox的状态
            holder.cb.toggle();
            // 将CheckBox的选中状况记录下来
            mWeekAdapter.setIsSelected(arg2, holder.cb.isChecked());
        }
    });
    setTitleText(mTitle);
    return rootLayout;
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:32,代码来源:WeekPicker.java

示例15: 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.getLayoutParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。