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

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

源代码1 项目: delion   文件: WebappUrlBar.java
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
源代码2 项目: AndroidChromium   文件: WebappUrlBar.java
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
源代码3 项目: auid2   文件: CaptionedImageView.java
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
源代码4 项目: auid2   文件: CaptionedImageView.java
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
源代码5 项目: auid2   文件: CaptionedImageView.java
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
源代码6 项目: 365browser   文件: WebappUrlBar.java
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
public ViewHolder(View view) {
    super(view);
    mTitle = (TextView) view.findViewById(R.id.lb_details_description_title);
    mSubtitle = (TextView) view.findViewById(R.id.lb_details_description_subtitle);
    mBody = (TextView) view.findViewById(R.id.lb_details_description_body);

    FontMetricsInt titleFontMetricsInt = getFontMetricsInt(mTitle);
    final int titleAscent = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_title_baseline);
    // Ascent is negative
    mTitleMargin = titleAscent + titleFontMetricsInt.ascent;

    mUnderTitleBaselineMargin = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_under_title_baseline_margin);
    mUnderSubtitleBaselineMargin = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_under_subtitle_baseline_margin);

    mTitleLineSpacing = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_title_line_spacing);
    mBodyLineSpacing = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_body_line_spacing);

    mBodyMaxLines = view.getResources().getInteger(
            R.integer.lb_details_description_body_max_lines);
    mBodyMinLines = view.getResources().getInteger(
            R.integer.lb_details_description_body_min_lines);

    mTitleFontMetricsInt = getFontMetricsInt(mTitle);
    mSubtitleFontMetricsInt = getFontMetricsInt(mSubtitle);
    mBodyFontMetricsInt = getFontMetricsInt(mBody);

    mTitle.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right,
                int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            mBody.setMaxLines(mTitle.getLineCount() > 1 ? mBodyMinLines : mBodyMaxLines);
        }
    });
}
 
public ViewHolder(View view) {
    super(view);
    mTitle = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_title);
    mSubtitle = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_subtitle);
    mActivity = (Activity) view.getContext();
    mInfoRow = new LinearLayout(mActivity);
    LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(Utils.convertDpToPixel(mActivity, 500), Utils.convertDpToPixel(mActivity,20));
    layout.setMargins(0,15,0,0);
    mInfoRow.setLayoutParams(layout);
    //Replace subtitle with our info row
    ViewGroup parent = (ViewGroup) view;
    int index = parent.indexOfChild(mSubtitle);
    parent.removeView(mSubtitle);
    parent.addView(mInfoRow, index);
    mBody = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_body);

    Paint.FontMetricsInt titleFontMetricsInt = getFontMetricsInt(mTitle);
    final int titleAscent = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_title_baseline);
    // Ascent is negative
    mTitleMargin = titleAscent + titleFontMetricsInt.ascent;

    mUnderTitleBaselineMargin = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_under_title_baseline_margin);
    mUnderSubtitleBaselineMargin = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_under_subtitle_baseline_margin);

    mTitleLineSpacing = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_title_line_spacing);
    mBodyLineSpacing = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_body_line_spacing);

    mBodyMaxLines = 6;
    mBodyMinLines = 4;

    mTitleFontMetricsInt = getFontMetricsInt(mTitle);
    mSubtitleFontMetricsInt = getFontMetricsInt(mSubtitle);
    mBodyFontMetricsInt = getFontMetricsInt(mBody);

    mTitle.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right,
                                   int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            mBody.setMaxLines(mTitle.getLineCount() > 1 ? mBodyMinLines : mBodyMaxLines);
        }
    });
}
 
源代码9 项目: Telegram-FOSS   文件: ChartHeaderView.java
public ChartHeaderView(Context context) {
    super(context);
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000");

    title = new TextView(context);
    title.setTextSize(15);
    title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0));

    back = new TextView(context);
    back.setTextSize(15);
    back.setTypeface(Typeface.DEFAULT_BOLD);
    back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0));

    dates = new TextView(context);
    dates.setTextSize(13);
    dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));

    datesTmp = new TextView(context);
    datesTmp.setTextSize(13);
    datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));
    datesTmp.setVisibility(View.GONE);


    back.setVisibility(View.GONE);
    back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut));
    zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom);
    back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null);
    back.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4));
    back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText)));

    datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f);
        dates.setPivotX(dates.getMeasuredWidth() * 0.7f);
    });
    recolor();
}
 
源代码10 项目: Telegram   文件: ChartHeaderView.java
public ChartHeaderView(Context context) {
    super(context);
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000");

    title = new TextView(context);
    title.setTextSize(15);
    title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0));

    back = new TextView(context);
    back.setTextSize(15);
    back.setTypeface(Typeface.DEFAULT_BOLD);
    back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0));

    dates = new TextView(context);
    dates.setTextSize(13);
    dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));

    datesTmp = new TextView(context);
    datesTmp.setTextSize(13);
    datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));
    datesTmp.setVisibility(View.GONE);


    back.setVisibility(View.GONE);
    back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut));
    zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom);
    back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null);
    back.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4));
    back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText)));

    datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f);
        dates.setPivotX(dates.getMeasuredWidth() * 0.7f);
    });
    recolor();
}
 
 方法所在类
 同类方法