How to make the first character much larger than other in a TextView

后端 未结 3 1661
谎友^
谎友^ 2020-12-16 23:51

I would like to display a paragraph of long text as follow. Here is the snapshot from Flipboard.

\"enter

3条回答
  •  离开以前
    2020-12-17 00:14

    Try this.

    Layout XML

    
    
    
    
    
    
    
    
    
    
    

    Activity class

    public class MainActivity extends Activity {
    private String inputString = "op British supermarket Tesco (LSE: TSCO) (NASDAQOTH: TSCDY.US) is due to announce its half year results on and this is the extra bit of spill text";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
    
        TextView bigChar = (TextView) findViewById(R.id.bigChar);
        final TextView sideText = (TextView) findViewById(R.id.sideText);
        final TextView spillText = (TextView) findViewById(R.id.spillText);
    
    
        ViewTreeObserver vto = sideText.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
               Layout layout = sideText.getLayout();  
               int numOfLines = layout.getLineEnd(2);
    
               // split the string now
               String spillTextString = inputString.substring(numOfLines, inputString.length());
               spillText.setText(spillTextString);
            }
        });
    }
    }
    

提交回复
热议问题