il a essayé et utiliser CustomTextView, mais tout le texte s'affiche en une seule ligne. je veux montrer le texte dans plusieurs lignes.Comment afficher du texte sur CustomTextView dans plusieurs lignes
ici mon code
<com.textdesign.views.CustomTextView
android:id="@+id/customTextview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:singleLine="false"
android:inputType="textMultiLine"
android:maxLines="40"
android:lines="20"
android:minLines="5"
android:text="this is sample text for multi-lines\nthis is sample text for multi-lines\nthis is sample text for multi-lines\nthis is sample text for multi-lines"
android:textStyle="bold" />
je minLines
, maxLines
, singleLine="false"
, inputType="textMultiLine"
mais toujours montrer comme ceci:
classe ici mon CustomTextView j'ai cacher une partie de mon code cette le code affiche également le texte sur une seule ligne.
public class CustomTextView extends AppCompatTextView {
//Shadow Variable
public static int shadow_length = 30;
public int x_direction = 1;
public int y_direction = 1;
boolean shadow_Enable = false;
int color = Color.BLACK;
float[] hsv = new float[]{0, 0, 0};
int getcol;
Paint paint;
Paint paint1;
Paint paint2;
public CustomTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet,android.R.attr.textViewStyle);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(getTextSize());
}
@Override
protected void onDraw(Canvas canvas) {
getPaint().setMaskFilter(null);
TextPaint textPaint = getPaint();
float x_position = (getWidth() - getPaint().measureText(getText().toString()))/2f;
float y_position = (int) ((getHeight()/2) - ((textPaint.descent() + textPaint.ascent())/2));
getPaint().setColor(shadowColor);
//Center point for transformation
PointF center_Point = new PointF(getWidth()/2f, getHeight()/2f);
Camera camera = new Camera();
canvas.drawText(getText().toString(), x_position, y_position, getPaint());
}
}
affichez votre classe textview personnalisée –
Ce n'est pas votre XML qui cause le problème. Avec un 'TextView' non modifié et votre XML dans un 'RelativeLayout', j'obtiens quatre lignes (dans le coin supérieur gauche, cependant). – kalabalik
Pour que nous puissions vous aider, vous devez ajouter votre fichier XML complet et le code de CustomTextView. – Frank