當前位置: 首頁>>代碼示例>>Java>>正文


Java ListView.setLayoutParams方法代碼示例

本文整理匯總了Java中android.widget.ListView.setLayoutParams方法的典型用法代碼示例。如果您正苦於以下問題:Java ListView.setLayoutParams方法的具體用法?Java ListView.setLayoutParams怎麽用?Java ListView.setLayoutParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.ListView的用法示例。


在下文中一共展示了ListView.setLayoutParams方法的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包/類
/**
 * @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

示例3: 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:zhuyu1022,項目名稱:amap,代碼行數:22,代碼來源:MIP_ListViewHeight.java

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

示例5: 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:Lazyeraser,項目名稱:DereHelper,代碼行數:19,代碼來源:Utils.java

示例6: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 動態設置ListView的高度
 * @param listView ListView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    if(listView == null) return;

    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:wzx54321,項目名稱:XinFramework,代碼行數:25,代碼來源:ViewFinder.java

示例7: 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,代碼來源:UserSettingFragment.java

示例8: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 計算ListView的高度, 重置ListView的高度.
 * 
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView)
{
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null)
	{
		return;
	}

	View listItem = null;
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++)
	{
		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:benniaobuguai,項目名稱:android-project-gallery,代碼行數:27,代碼來源:ViewUtils.java

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

示例10: onCreateView

import android.widget.ListView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	View v = inflater.inflate(R.layout.fragment_buy_ticket_info, null);
	lvInfos = (ListView) v.findViewById(R.id.buyTicketInfo_lvInfos);
	MyDatabase myDB = new MyDatabase(this.getActivity());
	mAdapter= new SimpleAdapter(this.getActivity(), mLstDatas, R.layout.item_buy_ticket_info,
			new String[]{MyDatabase.KEY, MyDatabase.VALUE},
			new int[]{R.id.item_buy_ticket_info_tvQuestion, R.id.item_buy_ticket_info_tvAnswer}
			);
	lvInfos.setAdapter(mAdapter);
	myDB.closeDB();
	notifyAdapterDataChanged(myDB.getTicketInfos(0));
	MyUtils.setListViewHeightBasedOnChildren(lvInfos);  //設置ListView全部顯示
	ViewGroup.LayoutParams params = lvInfos.getLayoutParams();
	
	params.height += 3000;   //方法不太準,人為校正高度
	lvInfos.setLayoutParams(params);
	sv1 = (ScrollView)v.findViewById(R.id.buyTicketInfo_sv1);
	sv1.smoothScrollTo(0, 20);
	return v;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:23,代碼來源:BuyTicketInfoFragment.java

示例11: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
public static void setListViewHeightBasedOnChildren(ListView lv){  
	ListAdapter listAdapter = lv.getAdapter();
    int listViewHeight = 0;  
    int adaptCount = listAdapter.getCount();  
    for(int i=0;i<adaptCount;i++){  
        View temp = listAdapter.getView(i,null,lv);  
        temp.measure(0,0);  
        listViewHeight += temp.getMeasuredHeight();  
    }  
    LayoutParams layoutParams = lv.getLayoutParams();  
    layoutParams.width = LayoutParams.MATCH_PARENT;  
    layoutParams.height = listViewHeight;  
    lv.setLayoutParams(layoutParams);  
}
 
開發者ID:Jay-Ping,項目名稱:newIPlay,代碼行數:15,代碼來源:FixedViewUtil.java

示例12: setItemsWithoutChk

import android.widget.ListView; //導入方法依賴的package包/類
public void setItemsWithoutChk(CharSequence[] items,
                               AdapterView.OnItemClickListener onItemClickListener) {
    ListView listview = new ListView(content.getContext());
    listview.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
    DialogAdapter adapter = new DialogAdapter(items);
    adapter.setShowChk(false);
    listview.setDivider(null);
    listview.setAdapter(adapter);
    listview.setOnItemClickListener(onItemClickListener);
    setContent(listview, 0);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:12,代碼來源:CommonDialog.java

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

示例14: 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,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:UIHelper.java

示例15: setupTableDataView

import android.widget.ListView; //導入方法依賴的package包/類
private void setupTableDataView(final AttributeSet attributes, final int styleAttributes) {
    final LayoutParams dataViewLayoutParams = new LayoutParams(getWidthAttribute(attributes), LayoutParams.MATCH_PARENT);

    if (isInEditMode()) {
        tableDataAdapter = new EditModeTableDataAdapter(getContext());
    } else {
        tableDataAdapter = new DefaultTableDataAdapter(getContext());
    }
    tableDataAdapter.setRowBackgroundProvider(dataRowBackgroundProvider);

    tableDataView = new ListView(getContext(), attributes, styleAttributes);

    tableDataView.setOnItemClickListener(new InternalDataClickListener());
    tableDataView.setOnItemLongClickListener(new InternalDataLongClickListener());
    tableDataView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tableDataView.setAdapter(tableDataAdapter);
    tableDataView.setId(R.id.table_data_view);
    tableDataView.setOnScrollListener(new InternalOnScrollListener());

    swipeRefreshLayout = new SwipeRefreshLayout(getContext());
    swipeRefreshLayout.setLayoutParams(dataViewLayoutParams);
    swipeRefreshLayout.addView(tableDataView);
    swipeRefreshLayout.setColorSchemeColors(headerColor);
    swipeRefreshLayout.setEnabled(false);

    addView(swipeRefreshLayout);
}
 
開發者ID:datalink747,項目名稱:Sortable_tableview_soussidev,代碼行數:28,代碼來源:TableView.java


注:本文中的android.widget.ListView.setLayoutParams方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。