List of usage examples for android.widget LinearLayout getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override/*from w w w . ja v a 2 s . c o m*/ protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container); txtContainer.measure(0, 0); int currentWidth = txtContainer.getMeasuredWidth(); int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35); nameLbl.measure(0, 0); int nameWidth = nameLbl.getMeasuredWidth(); int priceWidth = 0; if (row.hasPrice) { TextView priceLbl = (TextView) v.findViewById(R.id.price); priceLbl.measure(0, 0); priceWidth = priceLbl.getMeasuredWidth(); ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams(); lpPrice.width = priceWidth; priceLbl.setLayoutParams(lpPrice); priceLbl.requestLayout(); } ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams(); if (maxWidth > 0 && currentWidth < maxWidth) { if (maxWidth - priceWidth > nameWidth) { lpName.width = nameWidth; } else { lpName.width = maxWidth - priceWidth; } } else { lpName.width = maxWidth - priceWidth; } nameLbl.setLayoutParams(lpName); nameLbl.requestLayout(); } }); }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateLog(JSONArray jsonLogged) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); int hour = utc.get(Calendar.HOUR_OF_DAY); int max_hour = 0; int max_height = 100; LinearLayout hll = (LinearLayout) findViewById(R.id.time_log); if (hll == null) return;/*from ww w .j a va2 s .c om*/ hll.removeAllViews(); try { max_hour = jsonLogged.getInt(0); for (int i = 1; i < jsonLogged.length(); i++) { max_hour = Math.max(max_hour, jsonLogged.getInt(i)); } for (int i = 0; i < jsonLogged.length(); i++) { int height = (int) Math.ceil(max_height * jsonLogged.getInt(i) / max_hour); LinearLayout ll = (LinearLayout) context.getLayoutInflater().inflate(R.layout.list_item_log, null); ImageView iv = (ImageView) ll.findViewById(R.id.min_cell); iv.getLayoutParams().height = height; iv.getLayoutParams().width = hll.getWidth() / 24; TextView tv = (TextView) ll.findViewById(R.id.hour_no); tv.setText(i + ""); if (hour == i) tv.setBackgroundColor(0xFFFFFF33); ImageView sv = (ImageView) ll.findViewById(R.id.space_cell); sv.getLayoutParams().height = 100 - height; hll.addView(ll); } } catch (JSONException e) { e.printStackTrace(); } }