Justifying text inside a TextView in android

前端 未结 4 1400
醉话见心
醉话见心 2021-01-13 10:43

So, as most of you know, there is no text justifying inside a TextView in Android. So, I built a custom TextView to get around the problem. However, for some reason, sometim

4条回答
  •  逝去的感伤
    2021-01-13 10:54

    Try this way to justify text, it works for me

    public class MainActivity extends Activity {
    
        private JustifiedTextView mJTv;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mJTv=(JustifiedTextView) findViewById(R.id.activity_main_jtv_text);
            mJTv.setText(getResources().getString(R.string.test));
            mJTv.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
            mJTv.setLineSpacing(15);
            mJTv.setBackgroundColor(Color.RED);
            mJTv.setAlignment(Align.LEFT);
            mJTv.setTypeFace(Typeface.createFromAsset(getAssets(), "fonts/naskh_bold.ttf"));
    
        }
    }
    

    XML

    
    
        
        
    
    
    

    https://github.com/navabi/JustifiedTextView

    https://github.com/ufo22940268/android-justifiedtextview

    https://github.com/PareshMayani/Android-JustifyText

提交回复
热议问题