android.widget.TextView#requestLayout ( )源码实例Demo

下面列出了android.widget.TextView#requestLayout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                               List<View> sharedElementSnapshots) {
    TextView initialView = getTextView(sharedElements);

    if (initialView == null) {
        Log.w(TAG, "onSharedElementEnd: No shared TextView, skipping");
        return;
    }

    // Setup the TextView's end values.
    initialView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTargetViewTextSize);
    ViewUtils.setPaddingStart(initialView, mTargetViewPaddingStart);

    // Re-measure the TextView (since the text size has changed).
    int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    initialView.measure(widthSpec, heightSpec);
    initialView.requestLayout();
}
 
源代码2 项目: mage-android   文件: ObservationListAdapter.java
@Override
protected void onPostExecute(ObservationProperty property) {
    if (isCancelled()) {
        property = null;
    }

    TextView textView = reference.get();
    if (textView != null) {
        if (property == null || property.isEmpty()) {
            textView.setVisibility(View.GONE);
        } else {
            textView.setText(property.getValue().toString());
            textView.setVisibility(View.VISIBLE);
        }

        textView.requestLayout();
    }
}
 
源代码3 项目: CoolSignIn   文件: TextSharedElementCallback.java
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                               List<View> sharedElementSnapshots) {
    TextView initialView = getTextView(sharedElements);

    if (initialView == null) {
        Log.w(TAG, "onSharedElementEnd: No shared TextView, skipping");
        return;
    }

    // Setup the TextView's end values.
    initialView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTargetViewTextSize);
    ViewUtils.setPaddingStart(initialView, mTargetViewPaddingStart);

    // Re-measure the TextView (since the text size has changed).
    int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    initialView.measure(widthSpec, heightSpec);
    initialView.requestLayout();
}
 
源代码4 项目: appinventor-extensions   文件: TextViewUtil.java
/**
 * Sets the font typeface for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param typeface  one of @link Component#TYPEFACE_DEFAULT},
 *                  {@link Component#TYPEFACE_SERIF},
 *                  {@link Component#TYPEFACE_SANSSERIF} or
 *                  {@link Component#TYPEFACE_MONOSPACE}
 * @param bold true for bold, false for not bold
 * @param italic true for italic, false for not italic
 */
public static void setFontTypeface(TextView textview, int typeface,
    boolean bold, boolean italic) {
  Typeface tf;
  switch (typeface) {
    default:
      throw new IllegalArgumentException();

    case Component.TYPEFACE_DEFAULT:
      tf = Typeface.DEFAULT;
      break;

    case Component.TYPEFACE_SERIF:
      tf = Typeface.SERIF;
      break;

    case Component.TYPEFACE_SANSSERIF:
      tf = Typeface.SANS_SERIF;
      break;

    case Component.TYPEFACE_MONOSPACE:
      tf = Typeface.MONOSPACE;
      break;
  }

  int style = 0;
  if (bold) {
    style |= Typeface.BOLD;
  }
  if (italic) {
    style |= Typeface.ITALIC;
  }
  textview.setTypeface(Typeface.create(tf, style));
  textview.requestLayout();
}
 
源代码5 项目: aurora-imui   文件: LoadImageAsync.java
@Override
protected void onPostExecute(Drawable drawable) {
    TextView textView = mTextView.get();
    if (drawable != null && textView != null) {
        mDrawable.get().drawable = drawable;
        textView.requestLayout();
    }
}
 
源代码6 项目: YiZhi   文件: PlatformPageAdapter.java
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
源代码7 项目: enjoyshop   文件: PlatformPageAdapter.java
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
源代码8 项目: Camera-Roll-Android-App   文件: AlbumHolder.java
public void setAlbum(Album album) {
    if (album == null) {
        //Error album
        album = MediaProvider.getErrorAlbum();
    }

    this.album = album;

    TextView nameTv = itemView.findViewById(R.id.name);
    nameTv.setText(album.getName());
    //to fix ellipsize
    nameTv.requestLayout();
    //pinned indicator
    /*Drawable pinIndicator = null;
    if (album.pinned) {
        pinIndicator = AppCompatResources
                .getDrawable(getContext(), R.drawable.pin_indicator);
        if (pinIndicator != null) {
            int color = nameTv.getTextColors().getDefaultColor();
            DrawableCompat.wrap(pinIndicator);
            DrawableCompat.setTint(pinIndicator, color);
            DrawableCompat.unwrap(pinIndicator);
        }
    }
    nameTv.setCompoundDrawablesRelativeWithIntrinsicBounds(
            null, null, pinIndicator, null);*/

    //set album itemCount
    int itemCount = album.getAlbumItems().size();
    boolean oneItem = itemCount == 1;
    String count = getContext().getString(oneItem ?
            R.string.item_count : R.string.items_count, itemCount);
    ((TextView) itemView.findViewById(R.id.count)).setText(Html.fromHtml(count));

    ImageView hiddenFolderIndicator = itemView.findViewById(R.id.hidden_folder_indicator);
    if (hiddenFolderIndicator != null) {
        hiddenFolderIndicator
                .setVisibility(album.isHidden() ? View.VISIBLE : View.GONE);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !(album instanceof VirtualAlbum)) {
        ImageView removableStorageIndicator = itemView.findViewById(R.id.removable_storage_indicator);
        if (removableStorageIndicator != null) {
            try {
                boolean removable = Environment
                        .isExternalStorageRemovable(new File(album.getPath()));
                removableStorageIndicator
                        .setVisibility(removable ? View.VISIBLE : View.GONE);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    }
}
 
源代码9 项目: LQRWeChat   文件: PlatformPageAdapter.java
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
源代码10 项目: ScalableLayout   文件: MainActivity.java
public void onClick_SetMoreText(View view) {
    TextView tv = (TextView) findViewById(R.id.tv_moretext);
    tv.setText(tv.getText() + "커");
    tv.requestLayout();
}
 
源代码11 项目: ScalableLayout   文件: MainActivity.java
public void onClick_SetLessText(View view) {
    TextView tv = (TextView) findViewById(R.id.tv_moretext);
    tv.setText(tv.getText().subSequence(1, tv.getText().length()));
    tv.requestLayout();
}
 
源代码12 项目: APDE   文件: EditorActivity.java
/**
 * Fix inconsistencies in the vertical distribution of the content area views
 */
public void refreshMessageAreaLocation() {
	//Obtain some references
	final View content = findViewById(R.id.content);
	final View console = findViewById(R.id.console_wrapper);
	final View code = getSelectedCodeAreaScroller();
	final TextView messageArea = (TextView) findViewById(R.id.message);
	final FrameLayout autoCompileProgress = findViewById(R.id.auto_compile_progress_wrapper);
	
	if (firstResize) {
		//Use some better layout parameters - this switches from fractions/layout weights to absolute values
		code.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, code.getHeight()));
		console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, console.getHeight()));

		firstResize = false;
	}
	
	messageArea.requestLayout();
	
	messageArea.post(() -> {
		//We need to use this in case the message area is partially off the screen
		//This is the DESIRED height, not the ACTUAL height
		message = getTextViewHeight(getApplicationContext(), messageArea.getText().toString(), messageArea.getTextSize(), findViewById(R.id.message_char_insert_wrapper).getWidth(), messageArea.getPaddingTop());

		int consoleSize = content.getHeight() - code.getHeight() - message - (extraHeaderView != null ? extraHeaderView.getHeight() : 0) - tabBarContainer.getHeight() - autoCompileProgress.getHeight();

		//We can't shrink the console if it's hidden (like when the keyboard is visible)...
		//...so shrink the code area instead
		if (consoleSize < 0 || consoleWasHidden || keyboardVisible) {
			console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0));
			code.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
					content.getHeight() - message - (extraHeaderView != null ? extraHeaderView.getHeight() : 0) - tabBarContainer.getHeight() - autoCompileProgress.getHeight()));

			consoleWasHidden = true;
		} else {
			console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, consoleSize));

			consoleWasHidden = false;
		}
	});
}
 
源代码13 项目: appinventor-extensions   文件: TextViewUtil.java
/**
 * Sets the font size for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param size  font size in pixel
 */
public static void setFontSize(TextView textview, float size) {
  textview.setTextSize(size);
  textview.requestLayout();
}
 
源代码14 项目: appinventor-extensions   文件: TextViewUtil.java
/**
 * Sets the text for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param text  new text to be shown
 */
public static void setTextHTML(TextView textview, String text) {
  textview.setText(Html.fromHtml(text));
  textview.requestLayout();
}
 
源代码15 项目: appinventor-extensions   文件: TextViewUtil.java
/**
 * Sets the text for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param text  new text to be shown
 */
public static void setText(TextView textview, String text) {
  textview.setText(text);
  textview.requestLayout();
}
 
源代码16 项目: appinventor-extensions   文件: TextViewUtil.java
/**
 * Sets the padding for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param padding  left and right padding to be set
 */
public static void setPadding(TextView textview, int padding) {
  textview.setPadding(padding, padding, 0, 0);
  textview.requestLayout();
}
 
 方法所在类
 同类方法