本文整理匯總了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();
}