Example usage for android.widget TextView setMaxLines

List of usage examples for android.widget TextView setMaxLines

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setMaxLines(int maxLines) 

Source Link

Document

Sets the height of the TextView to be at most maxLines tall.

Usage

From source file:com.skytree.epubtest.BookViewActivity.java

public View makeResultItem(SearchResult sr, int mode) {
    int inlineColor = Color.rgb(133, 105, 75);
    int headColor = Color.rgb(94, 61, 34);
    int textColor = Color.rgb(50, 40, 40);

    SkyLayout view = new SkyLayout(this);
    int itemWidth = ps(370);
    int itemHeight = ps(190);

    this.setFrame(view, 0, 0, itemWidth, itemHeight);

    TextView chapterLabel = null;//from   w  ww  .  j  a  v  a 2 s .  com
    TextView positionLabel = null;
    TextView textLabel = null;
    Button itemButton = null;
    itemButton = new Button(this);
    itemButton.setBackgroundColor(Color.TRANSPARENT);
    itemButton.setOnClickListener(listener);
    this.setFrame(itemButton, 0, 0, itemWidth, itemHeight);

    if (mode == 0) { // Normal case
        int ci = sr.chapterIndex;
        String chapterText = "";
        chapterText = sr.chapterTitle;
        String positionText = String.format("%d/%d", sr.pageIndex + 1, sr.numberOfPagesInChapter);
        if (chapterText == null || chapterText.isEmpty()) {
            chapterText = "Chapter " + ci;
        }
        if (sr.pageIndex < 0 || sr.numberOfPagesInChapter < 0) {
            positionText = "";
        }
        chapterLabel = this.makeLabel(3090, chapterText, Gravity.LEFT, 15, headColor);
        positionLabel = this.makeLabel(3091, positionText, Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.text, Gravity.LEFT, 15, textColor);
        itemButton.setId(100000 + searchResults.size());
    } else if (mode == 1) { // Paused
        chapterLabel = this.makeLabel(3090, getString(R.string.searchmore) + "....", Gravity.CENTER, 18,
                headColor);
        //         positionLabel    = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".",
                Gravity.CENTER, 16, textColor);
        itemButton.setId(3093);
    } else if (mode == 2) { // finished
        chapterLabel = this.makeLabel(3090, getString(R.string.searchfinished), Gravity.CENTER, 18, headColor);
        //         positionLabel    = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".",
                Gravity.CENTER, 16, textColor);
        itemButton.setId(3094);
    }

    textLabel.setMaxLines(3);

    if (mode == 0) {
        this.setFrame(chapterLabel, ps(20), ps(20), ps(270), ps(30));
        this.setFrame(positionLabel, itemWidth - ps(85), ps(20), ps(70), ps(30));
        this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20));
    } else {
        this.setFrame(chapterLabel, ps(20), ps(20), ps(350), ps(40));
        //         this.setFrame(positionLabel, itemWidth-ps(80), ps(20),ps(70),ps(30));
        this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20));
    }

    view.addView(chapterLabel);
    if (mode == 0)
        view.addView(positionLabel);
    view.addView(textLabel);
    view.addView(itemButton);

    RectShape crs = new RectShape();
    SkyDrawable cd = new SkyDrawable(crs, Color.TRANSPARENT, inlineColor, 1);
    view.setBackgroundDrawable(cd);

    return view;
}