Java Code Examples for android.widget.ListView.setLayoutParams()

The following are Jave code examples for showing how to use setLayoutParams() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: exciting-app   File: Utils.java   View Source Code Vote up 6 votes
/**
 * @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);
}
 
Example 2
Project: FreeStreams-TVLauncher   File: Tools.java   View Source Code Vote up 6 votes
/**
 * @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);
}
 
Example 3
Project: amap   File: MIP_ListViewHeight.java   View Source Code Vote up 6 votes
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);
}
 
Example 4
Project: Viajes   File: Utils.java   View Source Code Vote up 6 votes
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();
}
 
Example 5
Project: DereHelper   File: Utils.java   View Source Code Vote up 6 votes
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);
}
 
Example 6
Project: XinFramework   File: ViewFinder.java   View Source Code Vote up 6 votes
/**
 * 动态设置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);
}
 
Example 7
Project: HiBangClient   File: UserSettingFragment.java   View Source Code Vote up 6 votes
/***
 * 动态设置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);
}
 
Example 8
Project: android-project-gallery   File: ViewUtils.java   View Source Code Vote up 6 votes
/**
 * 计算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);
}
 
Example 9
Project: AutoInteraction-Library   File: Util.java   View Source Code Vote up 6 votes
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);
}
 
Example 10
Project: HiBangClient   File: RegSchoolActivity.java   View Source Code Vote up 6 votes
/***
 * 动态设置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);
}
 
Example 11
Project: Huochexing12306   File: BuyTicketInfoFragment.java   View Source Code Vote up 6 votes
@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;
}
 
Example 12
Project: newIPlay   File: FixedViewUtil.java   View Source Code Vote up 5 votes
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);  
}
 
Example 13
Project: OSchina_resources_android   File: CommonDialog.java   View Source Code Vote up 5 votes
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);
}
 
Example 14
Project: Orin   File: ViewUtil.java   View Source Code Vote up 5 votes
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;
        }

    }
 
Example 15
Project: boohee_v5.6   File: UIHelper.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 16
Project: boohee_v5.6   File: ListViewUtils.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 17
Project: Sortable_tableview_soussidev   File: TableView.java   View Source Code Vote up 5 votes
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);
}
 
Example 18
Project: PlusGram   File: ThemStore.java   View Source Code Vote up 4 votes
@Override
public View createView(final Context context) {
    actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("ThemeStore", R.string.ThemeStore));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });


    fragmentView = new FrameLayout(context);
    fragmentView.setLayoutParams(new FrameLayout.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));


    FrameLayout frameLayout = (FrameLayout) fragmentView;


    listView = new ListView(context);

    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
    listView.setBackgroundColor(preferences.getInt("prefBGColor", 0xffffffff));
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    int def = preferences.getInt("themeColor", AndroidUtilities.defColor);
    int hColor = preferences.getInt("prefHeaderColor", def);
    AndroidUtilities.setListViewEdgeEffectColor(listView, /*AvatarDrawable.getProfileBackColorForId(5)*/ hColor);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
    layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    listView.setLayoutParams(layoutParams);

    progressDialog = new ProgressDialog(context);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setMessage(context.getString(R.string.Loading));

    if (Cashing.themes.size() < 1) {
        progressDialog.show();
        new getThemes(context, constant.GET_THEMES).execute();
    } else {
        themes = Cashing.themes;
        refreshDisplay(context);
    }

    return fragmentView;
}
 
Example 19
Project: Orin   File: ArtistDetailActivity.java   View Source Code Vote up 4 votes
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();

    }
 
Example 20
Project: Android-Music-Player   File: Main.java   View Source Code Vote up 4 votes
public Main(Context context, int width, int height) {
    super(context, width, height);
    setBackgroundColor(0x00000000);
    This = this;

    squre sqTitle = new squre(width, Ui.cd.getHt(50),0,0);
    sqTitle.setColor(titleBack.Color0);
    addShape(sqTitle);

    squre btmSq = new squre(width, Ui.cd.getHt(120),0,height  - Ui.cd.getHt(120 + 60));
    btmSq.setColor(btmBack.Color0);
    addShape(btmSq);

    squre sq = new squre(width,height - Ui.cd.getHt(50) - btmSq.height + - Ui.cd.getHt(60),0, Ui.cd.getHt(50));
    sq.setColor(backgroundImg.Color0);
    addShape(sq);

    squre bmLine = new squre(width, Ui.cd.getHt(2) ,0,btmSq.y+ btmSq.height);
    bmLine.setColor(backgroundImg.Color0);
    addShape(bmLine);

    squre volumeBack = new squre(width, Ui.cd.getHt(60-2) ,0,bmLine.y+ bmLine.height);
    volumeBack.setColor(btmBack.Color0);
    addShape(volumeBack);

    VolumeRocker Vr = new VolumeRocker(getContext(),width,(int)volumeBack.height);
    Vr.setBackgroundResource(0);
    Vr.setY(volumeBack.y);

    addView(Vr);

    FMText title = textImg.getFMText(context,"Equalizer Presets", Ui.cd.getHt(18));
    title.img.setColor(textColor.Color0);
    title.InCenter(width, Ui.cd.getHt(50));
    title.setX(Ui.cd.getHt(10));
    addView(title);

    addWhells((int) btmSq.y, (int) btmSq.height);

    presetAdapter data;
    listview = new ListView(getContext());
    listview.setLayoutParams(new FrameLayout.LayoutParams((int)sq.width,(int)sq.height));
    listview.setY(sq.y);
    listview.setDivider(null);
    listview.setBackgroundResource(0);
    //listview.setBackgroundColor(com.shape.home.slider.backgroundImg.Color0);
    data = new presetAdapter(){
        @Override
        public void onReload(){
            if(listview != null){
                refreshData();
            }
        }
    };
    listview.setAdapter(data);
    addView(listview);

    final radioBtn rBtn = new radioBtn(getContext(), Ui.cd.getHt(95), Ui.cd.getHt(40));
    rBtn.InCenter(width, Ui.cd.getHt(50));
    rBtn.setX(width - rBtn.width - Ui.cd.getHt(5));
    addView(rBtn);


    Ui.ef.playerEvent.addEvent(new EventCall(new int[]{playerEvents.EQ_CHANGED, Ui.ef.Event_onBind}){
        @Override
        public void onCall(int eventId) {
            refreshData();
            rBtn.switchBtn(Ui.ef.MusicPlayer.handler.EQs.isOn);
        }
    });

}