Example usage for android.widget TextView getHeight

List of usage examples for android.widget TextView getHeight

Introduction

In this page you can find the example usage for android.widget TextView getHeight.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

private TextView createSpyingColumnForTableRow(String text, final int rowId, final float weight,
        Context context) {//from   www. j  av  a 2 s . c  o m
    final SpyingTextView view = new SpyingTextView(context);
    populateColumn(view, context, weight);
    view.heightCatch = true;
    view.setHeightRunnable(new Runnable() {
        @Override
        public void run() {
            final TableRow row = (TableRow) getChildAt(rowId);
            final int childCount = row.getChildCount();

            int maxHeight = 0;
            for (int i = 0; i < childCount; i++) {
                final TextView childAt = (TextView) row.getChildAt(i);
                maxHeight = Math.max(maxHeight, childAt.getHeight());
            }

            for (int i = 0; i < childCount; i++) {
                final TextView childAt = (TextView) row.getChildAt(i);
                childAt.setLayoutParams(
                        new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, maxHeight, weight));
            }

            invalidate();
        }
    });
    view.setText(text);
    return view;
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

@Override
public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) {
        // Only animate text changes that occur from user input.
        return;//from ww w . j  a  v  a  2  s  . c o  m
    }

    // Calculate the values needed to perform the scale and translation
    // animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
}

From source file:com.community.yuequ.bottombar.BottomBar.java

private void updateTitleBottomPadding() {
    if (tabContainer == null) {
        return;/*w ww .j  av  a2  s .  com*/
    }

    int childCount = getTabCount();

    for (int i = 0; i < childCount; i++) {
        View tab = tabContainer.getChildAt(i);
        TextView title = (TextView) tab.findViewById(R.id.bb_bottom_bar_title);

        if (title == null) {
            continue;
        }

        int baseline = title.getBaseline();
        int height = title.getHeight();
        int paddingInsideTitle = height - baseline;
        int missingPadding = tenDp - paddingInsideTitle;

        if (missingPadding > 0) {
            title.setPadding(title.getPaddingLeft(), title.getPaddingTop(), title.getPaddingRight(),
                    missingPadding + title.getPaddingBottom());
        }
    }
}

From source file:com.desno365.mods.Tabs.FragmentTab3.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab3, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_laser_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.laser.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.laser_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.laser.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.laser_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.laser.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab3); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from  w ww .  j  ava2s .  com
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab2.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab2, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_portal_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.portal.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.portal_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.portal.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.portal_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.portal.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab2); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w  w. ja  v  a2  s  . c o  m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab7.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab7, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_unreal_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.unreal.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.unreal_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.unreal.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.unreal_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.unreal.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab7); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w w .  j av  a2s  . c o  m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab6.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab6, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_guns_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.desnoGuns.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.guns_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.desnoGuns.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.guns_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.desnoGuns.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab6); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/* w  w  w. j av a  2  s.c om*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab4.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab4, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_turrets_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.turrets.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.turrets_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.turrets.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.turrets_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.turrets.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab4); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w w. j  a  v  a  2 s .co m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab5.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab5, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_jukebox_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.jukebox.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.jukebox_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.jukebox.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.jukebox_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.jukebox.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab5); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//w ww . jav  a2s .  c om
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:bottombar.BottomBar.java

private void updateTitleBottomPadding() {
    int tabCount = getTabCount();

    if (tabContainer == null || tabCount == 0 || !isShiftingMode()) {
        return;// ww w .j a  v a2  s.  c  o m
    }

    for (int i = 0; i < tabCount; i++) {
        BottomBarTab tab = getTabAtPosition(i);
        TextView title = tab.getTitleView();

        if (title == null) {
            continue;
        }

        int baseline = title.getBaseline();
        int height = title.getHeight();
        int paddingInsideTitle = height - baseline;
        int missingPadding = tenDp - paddingInsideTitle;

        if (missingPadding > 0) {
            title.setPadding(title.getPaddingLeft(), title.getPaddingTop(), title.getPaddingRight(),
                    missingPadding + title.getPaddingBottom());
        }
    }
}