CustomTextViewを試してみましたが、すべてのテキストが1行で表示されます。私は複数の行にテキストを表示したい。複数行のCustomTextViewにテキストを表示する方法
ここに私のコード
<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" />
私はminLines
、maxLines
、singleLine="false"
、inputType="textMultiLine"
を使用しますが、まだ、このように表示さ:
ここに私のCustomTextViewクラスを私は私のコードの一部にこれを隠していますコードは1行でテキストも表示します。
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());
}
}
あなたのカスタムテキストビュークラスを表示します –
あなたのXMLはこの問題の原因ではありません。変更されていない「TextView」とあなたのXMLを「RelativeLayout」の中に入れて、私は4行(左上隅にあります)を取得します。 – kalabalik
私たちのお手伝いをするには、完全なXMLファイルとCustomTextViewのコードを追加する必要があります。 – Frank