本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}