2017-02-13 2 views
1

Versuchen Sie, Text zu rechtfertigen, aber ich bin nicht in der Lage zu tun, dass ich Text beginnen soll, beginnen Sie ein Ende bei gleichem Rand von der linken und rechten Seite. Wie geht das?Begründen Sie Text in Tetview

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="20dp" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:lineSpacingExtra="4dp" 
     android:layout_marginRight="3dp" 
     android:layout_marginLeft="3dp" 
     android:paddingBottom="20dp" 
     android:text="@string/about_us" 
     android:textColor="@color/black" 
     android:textSize="15sp"/> 
</LinearLayout> 
+0

können Sie sie überprüfen http://stackoverflow.com/questions/1292575/android-textview-justify-text –

Antwort

0

Vor allem Android nicht die volle Rechtfertigung unterstützen, aber wenn Sie Ihren Text rechtfertigen wollen versuchen, auf diese Weise

Sie einfach zu Ihrem build.gradle hinzufügen

dependencies { 
    compile 'com.github.bluejamesbond:textjustify-android:2.1.6' 
} 

https://github.com/bluejamesbond/TextJustify-Android

OR

diese Weise android

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

<ir.noghteh.JustifiedTextView 
     android:id="@+id/activity_main_jtv_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:padding="25dp" 
     xmlns:noghteh="http://noghteh.ir" 
     noghteh:text="@string/hello_world" 
     noghteh:textColor="@color/text" 
     noghteh:textSize="18sp" 
     > 
    </ir.noghteh.JustifiedTextView> 

https://github.com/navabi/JustifiedTextView

+0

JustifiedTextView können dies nicht lösen –

+0

verwendet in oncreateview –

+0

JustifiedTextView Sie dieses Symbol nicht lösen? ich füge diese Abhängigkeit hinzu, kompiliere 'com.github.bluejamesbond: textjudeify-android: 2.1.6' –

0

Begründen Text in Textview Versuchen.

 

String dis="You can write your content here"; 

String text_string="<html><body style=\"text-align:justify\">"+dis+"<body><html>"; 

TextView text=setText(fromHtml(text_string)); 
Verwandte Themen