Java Code Examples for android.widget.TextView#getLineHeight()

The following examples show how to use android.widget.TextView#getLineHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TinyCoach.java    From TinyDancer with MIT License 6 votes vote down vote up
public TinyCoach(Application context, FPSConfig config) {

        fpsConfig = config;

        //create meter view
        meterView = (TextView) LayoutInflater.from(context).inflate(R.layout.meter_view, null);

        //set initial fps value....might change...
        meterView.setText((int) fpsConfig.refreshRate + "");

        // grab window manager and add view to the window
        windowManager = (WindowManager) meterView.getContext().getSystemService(Service.WINDOW_SERVICE);

        int minWidth = meterView.getLineHeight()
                + meterView.getTotalPaddingTop()
                + meterView.getTotalPaddingBottom()
                + (int) meterView.getPaint().getFontMetrics().bottom;
        meterView.setMinWidth(minWidth);

        addViewToWindow(meterView);
    }
 
Example 2
Source File: ViewSwitcherWrapper.java    From Android-Notification with Apache License 2.0 6 votes vote down vote up
private void adjustTextViewHeight() {
    View view = getView();
    if (view == null) {
        return;
    }

    TextSwitcher textSwitcher = (TextSwitcher) view;
    TextView curr = (TextView) textSwitcher.getCurrentView();
    TextView next = (TextView) textSwitcher.getNextView();
    int currH = curr.getLineCount() * curr.getLineHeight();
    int nextH = next.getLineCount() * next.getLineHeight();
    if (currH != nextH) {
        curr.setHeight(currH);
        next.setHeight(currH);
    }
}
 
Example 3
Source File: LineUtils.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
public int getTopVisibleLine(TextView editor) {
    int lineHeight = editor.getLineHeight();
    if (lineHeight == 0) {
        return 0;
    }
    int line = editor.getScrollY() / lineHeight;
    if (line < 0) {
        return 0;
    }
    if (line >= editor.getLineCount()) {
        return editor.getLineCount() - 1;
    }
    return line;
}
 
Example 4
Source File: LineUtils.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
public int getBottomVisibleLine(TextView editor) {
    int lineHeight = editor.getLineHeight();
    if (lineHeight == 0) {
        return 0;
    }
    int line = Math.abs((editor.getScrollY() + editor.getHeight()) / lineHeight) + 1;
    if (line < 0) {
        return 0;
    }
    if (line >= editor.getLineCount()) {
        return editor.getLineCount() - 1;
    }
    return line;
}
 
Example 5
Source File: PushListAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureViewForPosition(View itemView, int position) {
    TextView dateText = (TextView) itemView.findViewById(R.id.push_date);
    TextView titleText = (TextView) itemView.findViewById(R.id.push_title);
    TextView descriptionText = (TextView) itemView.findViewById(R.id.push_description);
    ImageView iconImage = (ImageView) itemView.findViewById(R.id.push_icon_image);

    String title = entries.get(position).getTitle();
    if (title.equals(""))
        title = entries.get(position).getService().getName();
    String description = entries.get(position).getMessage();
    Date pushDate = entries.get(position).getLocalTimestamp();
    Bitmap icon = entries.get(position).getService().getIconBitmapOrDefault(context);

    dateText.setText(this.dateFormat.format(pushDate));
    titleText.setText(title);
    descriptionText.setText(description);
    iconImage.setImageBitmap(icon);

    TypedValue value = new TypedValue();
    DisplayMetrics metrics = new DisplayMetrics();

    context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true);
    ((WindowManager) (context.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getMetrics(metrics);

    int lineCount = selectedIndex == position ? descriptionText.getLineCount() : 0;
    int minHeight = (int) TypedValue.complexToDimension(value.data, metrics);
    int prefHeight = (lineCount + 2) * descriptionText.getLineHeight();
    itemView.getLayoutParams().height = prefHeight > minHeight ? prefHeight : minHeight;
}
 
Example 6
Source File: CharacteristicOperationFragment.java    From FastBle with Apache License 2.0 5 votes vote down vote up
private void addText(TextView textView, String content) {
    textView.append(content);
    textView.append("\n");
    int offset = textView.getLineCount() * textView.getLineHeight();
    if (offset > textView.getHeight()) {
        textView.scrollTo(0, offset - textView.getHeight());
    }
}
 
Example 7
Source File: TextUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 改变外框大小,适应文字
 * 如果当前文字只有一行,则缩到外框适应文字大小
 * 如果文字有多行,则宽度不变,缩小高度到适应文字大小
 * 文字外框的位置不变
 *
 * @param view
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void adjustSize(TextView view) {
    if (view != null && view.getLayoutParams() != null) {
        /*
        //更好的实现方式,但是ios那边不支持这种方式
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        view.setLayoutParams(layoutParams);*/

        // 废弃的实现方式,使用WRAP_CONTENT最简单,且这种方式算出来的width有bug
        // @Deprecated
        /*int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
        int width, height;
        if (lineCount > 1) {//多行,宽度不变,改变高度
            width = view.getWidth();
            height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
        } else {//一行,改变宽度&高度
             Paint paint = view.getPaint();
            width = (int) paint.measureText(view.getText().toString()) + view.getPaddingLeft() + view.getPaddingRight();
            height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
        }*/

        int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
        float width, height;
        if (lineCount > 1) {//多行,宽度不变,改变高度
            width = view.getWidth();
            height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
        } else {//一行,改变宽度&高度
            width = view.getPaddingLeft() + Layout.getDesiredWidth(view.getText(), view.getPaint()) + view.getPaddingRight();
            height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
        }

        if (view.getLayoutParams() != null) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.width = (int) width;
            layoutParams.height = (int) height;
            view.setLayoutParams(layoutParams);
        }
    }
}
 
Example 8
Source File: VerticalMarqueeTextView.java    From Android-Lib-VerticalMarqueeTextView with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the standard height (i.e. without text effects such as shadow) of all the text of
 * the given {@link TextView}.
 * @param textView The {@link TextView} to determine the height of all its text content.
 * @return The standard height of all the text content of the given {@link TextView}.
 */
private int heightOf(final TextView textView) {
    return textView.getLineCount() > 0 ? textView.getLineHeight() * textView.getLineCount() : 0;
}