Setting textSize in custom view results in huge text

前端 未结 2 1205
挽巷
挽巷 2021-02-02 06:07

I\'m calling the following in the constructor of my custom view:

private void style(Resources.Theme theme, AttributeSet attrs) {
    TypedArray a = theme.obtainS         


        
2条回答
  •  攒了一身酷
    2021-02-02 06:40

    Try the following instead:

    line1Size = a.getDimensionPixelSize(R.styleable.StackedTextView_line1_textSize, 0);
    line2Size = a.getDimensionPixelSize(R.styleable.StackedTextView_line2_textSize, 0);
    
    if (line1Size > 0) {
        holdr.textLine1.setTextSize(TypedValue.COMPLEX_UNIT_PX, line1Size);
    }
    if (line2Size > 0) {
        holdr.textLine2.setTextSize(TypedValue.COMPLEX_UNIT_PX, line2Size);
    }
    

提交回复
热议问题