循环通过TextView并设置大小

时间:2015-12-11 10:38:46

标签: java android loops textview

我试图遍历指定的大小列表并相应地更改TextView中文本的大小。我怎样才能正确地做到这一点?

public void TextBigger(View view) {
    int[] textViewSizes = new int[] {10, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    for(int i=0; i < textViewSizes.length; i++) {
        text_View.setTextSize(TypedValue.COMPLEX_UNIT_SP, i);
    }
}

1 个答案:

答案 0 :(得分:1)

//make these class scope
int currentTextSize = 0;
int[] textViewSizes = new int[] {10, 12, 13, 14, 15, 16, 17, 18, 19, 20 };

public void TextBigger(View view) {
    if(currentTextSize < textViewSizes.length - 1)
        currentTextSize++;
    text_View.setTextSize(TypedValue.COMPLEX_UNIT_SP, textViewSizes[currentTextSize]);
}