1

I have one layout it contains data which will display to user when he press textview.In that lay out it contain lot of data that's way i use one string resource file to display that data and by using setResource i will access that file when ever i want.Everything is fine it display the data but alignment of data is not good.I want data will display in the format of Justified.

Note -I already try the WebView ,it is working but it don't take resource file and i want use the textview only.

Following is the code.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/actionbar_textview"
    android:layout_margin="@dimen/fab_margin"
    /></LinearLayout>

TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview);
            textviewTitle.setText(getResources().getString(R.string.terms_services_title));

This R.string.terms_services_title file contain data.

YBDevi
  • 439
  • 5
  • 22

2 Answers2

0

Answer Here

Can I set property of Textview like justify?

No, you can't set justify textview in android. But you can set the justification to your text by taking webview instead of text view.

You may refer to this.

Code

import android.app.Activity;
 import android.os.Bundle;
 import android.webkit.WebView;

 public class Main extends Activity {

    WebView mWebView;

    @Override
     public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    mWebView = (WebView) findViewById(R.id.webview);    

       String text = "<html><body>"
        + "<p align=\"justify\">"                
           + getString(R.string.terms_services_title) 
         + "</p> "
         + "</body></html>";

     mWebView.loadData(text, "text/html", "utf-8");
     }
}

main.xml

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
     android:layout_height="fill_parent">
    <WebView
       android:id="@+id/webview"
    android:layout_width="fill_parent"
     android:layout_height="fill_parent" />
  </RelativeLayout>
Community
  • 1
  • 1
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
0

try the below one:-

Inside strings file put your string in html form

<string name="web_text">
<![CDATA[
<html>
 <head></head>
 <body style="text-align:justify;color:gray;background-color:black;">
  Your text here!!
 </body>
</html>
]]>
</string>

and use inside Java file like this

onCreate(Bundle savedInstanceState){
setContentView(R.layout.web_layout);
 WebView view = (WebView)findViewById(R.id.web_view);
    view.setVerticalScrollBarEnabled(false);
    view.loadData(getString(R.string.web_text), "text/html; charset=utf-8", "utf-8");
}

and inside web_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <WebView
        android:id="@+id/web_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></WebView>
</LinearLayout>
Aditi
  • 455
  • 4
  • 13