List of usage examples for android.widget TextView layout
@SuppressWarnings({ "unchecked" }) public void layout(int l, int t, int r, int b)
This is the second phase of the layout mechanism.
From source file:Main.java
protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) { TextView tv = new TextView(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(layoutParams);//from ww w . j a v a 2s.c o m tv.setText(contents); tv.setHeight(height); tv.setGravity(Gravity.CENTER_HORIZONTAL); tv.setWidth(width); tv.setDrawingCacheEnabled(true); tv.setTextColor(Color.BLACK); tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.buildDrawingCache(); Bitmap bitmapCode = tv.getDrawingCache(); return bitmapCode; }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public int captureBitmapCache(String in) { TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview); String tvText = tv.getText().toString(); float tvTextSize = tv.getTextSize(); int tvColor = tv.getCurrentTextColor(); Bitmap bitmap = null;//from w w w . j a va 2 s . c o m tv.setTextSize(36); tv.setTextColor(Color.CYAN); tv.setTypeface(Typeface.SANS_SERIF); tv.setText(in); while (bitmap == null) { // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.setDrawingCacheEnabled(true); tv.buildDrawingCache(true); bitmap = Bitmap.createBitmap(tv.getDrawingCache()); tv.destroyDrawingCache(); tv.setDrawingCacheEnabled(false); } FileOutputStream fos = null; int res = -1; try { fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME); if (fos != null) { bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); res = 0; } } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); res = -1; } tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize); tv.setTypeface(Typeface.MONOSPACE); tv.setText(tvText); tv.setTextColor(tvColor); return res; }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.DayPickerView.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final TextView leftButton; final TextView rightButton; if (SUtils.isLayoutRtlCompat(this)) { leftButton = mNextButton;/*from w w w . j av a 2 s. c o m*/ rightButton = mPrevButton; } else { leftButton = mPrevButton; rightButton = mNextButton; } final int width = right - left; final int height = bottom - top; mViewPager.layout(0, 0, width, height); final SimpleMonthView monthView = (SimpleMonthView) mViewPager.getChildAt(0).findViewById(R.id.month_view); final int monthHeight = monthView.getMonthHeight(); // final int monthHeight = 0; final int cellWidth = monthView.getCellWidth(); // Vertically center the previous/next buttons within the month // header, horizontally center within the day cell. final int leftDW = leftButton.getMeasuredWidth(); final int leftDH = leftButton.getMeasuredHeight(); final int leftIconTop = monthView.getPaddingTop() + (monthHeight - leftDH) / 2; final int leftIconLeft = monthView.getPaddingLeft() + (cellWidth - leftDW) / 2; leftButton.layout(leftIconLeft, leftIconTop, leftIconLeft + leftDW, leftIconTop + leftDH); final int rightDW = rightButton.getMeasuredWidth(); final int tvResetDW = tvReset.getMeasuredWidth(); final int rightDH = rightButton.getMeasuredHeight(); final int tvResetDH = tvReset.getMeasuredHeight(); final int rightIconTop = monthView.getPaddingTop() + (monthHeight - rightDH) / 2; final int tvResetIconTop = monthView.getPaddingTop() + (monthHeight - tvResetDH) / 2; final int rightIconRight1 = width - monthView.getPaddingRight() - (cellWidth - rightDW) / 2 - 60; final int rightIconRight = leftIconLeft + 180; rightButton.layout(rightIconRight, rightIconTop, rightIconRight + rightDW, rightIconTop + rightDH); tvReset.layout(rightIconRight1 - tvResetDW, tvResetIconTop, rightIconRight1, tvResetIconTop + tvResetDH); }
From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java
public void setActionBarLogoCounter(int count) { ImageView logo = (ImageView) findViewById(android.R.id.home); if (count < 1) { currentLogoCounter = 0;/*from w w w . j a va2 s . co m*/ logo.setVisibility(View.GONE); return; } else { logo.setVisibility(View.VISIBLE); } currentLogoCounter = count; TextView v = new TextView(getApp()); v.setText(new Integer(count).toString()); v.setBackgroundResource(R.drawable.sidebar_menu_counterbg); v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); v.setDrawingCacheEnabled(true); v.setTextColor(Color.WHITE); v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0); ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, 1); paramsExample.setMargins(0, 0, 0, 0); v.setHeight(SKDimensions.convertDpToPixel(20, getApp())); v.setLayoutParams(paramsExample); // this is the important code :) // Without it the view will have a dimension of 0,0 and the bitmap will be null v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b)); logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0); }