问题
my problem is this, using TextViewEx (https://github.com/bluejamesbond/TextJustify-Android) class texts to justify my android application works fine until the text over a carriage return appear \ n, when this happens the text is cut losing asin several lines of this, I need a solution to justify text without html injection, to change the font size if the application is open from mobile or from a tablet, if know what the problem is and can help me I thank you.
I will put the code in my application:
code xml:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="45dp"
android:layout_below="@+id/view1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:background="@drawable/background_border" >
<TextView
android:id="@+id/txt_fecha_promociones"
style="@style/fechaDentroxlarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="24/05/2014" />
<TextView
android:id="@+id/txt_titulo_promociones"
style="@style/tituloDentroxlarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_below="@+id/comparte"
android:text="Titulo" />
**<com.xxxxx.tools.TextViewEx
android:id="@+id/txt_noticia_promociones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img_promo"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:textSize="30sp"
android:text="noticia"
android:textColor="@color/txtBlanco" />**
<ImageView
android:id="@+id/comparte"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_toLeftOf="@+id/txt_fecha_promociones"
android:onClick="compartir"
android:src="@drawable/share_icon_white" />
<ImageView
android:id="@+id/img_promo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_titulo_promociones"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="@drawable/promo1" />
</RelativeLayout>
</ScrollView>
code java:
public class xxxxx extends NavegacionActivity {
TextView txt_servicio;
TextViewEx txt_descripcion;
TextView prueba;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_servicios_dentro);
setBehindContentView(R.layout.menu);
getSlidingMenu().setBehindOffset(100);
txt_servicio = (TextView) findViewById(R.id.txt_titulo_servicio);
txt_descripcion = (TextViewEx) findViewById(R.id.txt_descripcion_servicios);
Intent i = getIntent();
txt_servicio.setText(i.getStringExtra("servicio"));
txt_descripcion.setText(i.getStringExtra("descripcion"),true);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent i = new Intent(this, xxxx.class);
startActivity(i);
this.finish();
}
}
回答1:
Import the classes TextJustifyUtils.java
and TextViewEx.java
in the root of your project
In your XML Replace TextView --->> com.example.myaplication.TextViewEx
回答2:
Just go to TextViewEx.java and change to this code:
@Override
public void setPadding(int left, int top, int right, int bottom) {
DisplayMetrics metrics = getContext().getResources()
.getDisplayMetrics();
super.setPadding((int) ((left + (metrics.density * 10))), top,
(int) (right + (metrics.density * 10)),
(int) (bottom + (metrics.heightPixels * 1.5)));
Log.i("Log", "metrics : " + metrics);
}
来源:https://stackoverflow.com/questions/23801294/textviewex-textjustify