當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。