İçinde "Stackoverflow" yazan normal bir TextView'iniz olduğunu varsayalım, TextView'i -90 ° döndürmek, S'yi ekranın alt kısmına ve W'nin ekranın üst kısmına getirmek mümkün mü? Elbette metnimi bir resim olarak yazabilirim, döndürürüm ve bu şekilde kullanırım, ancak şu anda metinle ilgileniyorum. Teşekkürler.Android'de bir metin görünümünde dikey olarak yazmak mümkün mü?
cevap
Bu işlemi normalde örneğin
yapacağı gibi TextView'un ayarlayabilirsiniz: Metninizde karakterleri ters
<TextView android:id="@+id/txtview"
android:layout_height="fill_parent"
android:layout_width="wrap_content" />
ve
- için aktivitesinde bir işlev yazmak
- , her karakterden sonra
\n
ekleyiniz
ve sonra metni TextView olarak ayarlayın. Eğer \n
eklemek istemiyorsanız
, sen android:layout_width
boyutunu ayarlayabilir ve aynı hat ve hiçbir kesilmesi
Düzenleme Ben ise üzerinde oturan 2 karakter almamayı yazı tipi boyutu ile oynamak zorunda kalacak Seni doğru anladın, istediğin şeyi animasyon kullanarak alabilirsiniz. Örneğin
için
res/animation/myanim.xml
altında:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:duration="0" />
Size metin görünümü yerleştirilmesini istediğiniz yere tanımlamak için bu dosya ile oynamak zorunda kalacak. etkinlik olarak
:
TextView t = (TextView)findViewById(R.id.txtview);
String txt = "Stackoverflow";
t.setText(txt);
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
ranim.setFillAfter(true); //For the textview to remain at the same place after the rotation
t.setAnimation(ranim);
neyi ve aslında, her karakterin diğerinin üstünde olmasını istemiyorum, ama hepsi -90 ° döndürme ile ... bu mümkün mü? – Sephy
aha tamam - Sanırım şimdi ne demek istediğini biliyorum - Bunu nasıl yapacağımı bilmiyorum ama bunun hakkında düşüneceğim – ccheneson
Evet bu harika bir fikir. – Sephy
bu deneyin. Benim için iyi çalışıyor. Bir metin satırını dikey olarak görüntüleyebilir, ancak yalnızca bir satır. renkler, boyut, yastıklar, kenar boşlukları ve arka plan tüm iyi çalışıyor.
public class VerticalTextView extends TextView {
public VerticalTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
final ColorStateList csl = getTextColors();
final int color = csl.getDefaultColor();
final int paddingBottom = getPaddingBottom();
final int paddingTop = getPaddingTop();
final int viewWidth = getWidth();
final int viewHeight = getHeight();
final TextPaint paint = getPaint();
paint.setColor(color);
final float bottom = viewWidth * 9.0f/11.0f;
Path p = new Path();
p.moveTo(bottom, viewHeight - paddingBottom - paddingTop);
p.lineTo(bottom, paddingTop);
canvas.drawTextOnPath(getText().toString(), p, 0, 0, paint);
}
}
daha sonra API 11 veya kullanıyorsanız, sen deneyebilirsiniz:
TextView t = (TextView) findViewById(R.id.txtview);
String txt = "Stackoverflow";
t.setText(txt);
t.setRotation(90); // 90 degree rotation
ilklendirmesini boyamak için bu, metin izniyle ilgili sorunlara yol açacaktır. onMeasure() bunun için yeniden tanımlanmalıdır. –
Bence bu bir sorun değil, değil mi? Sadece genişlik ve yükseklik ... – Chris623
benim için çalıştı:
public class VerticalTextView extends TextView {
private int _width, _height;
private final Rect _bounds = new Rect();
public VerticalTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalTextView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// vise versa
_height = getMeasuredWidth();
_width = getMeasuredHeight();
setMeasuredDimension(_width, _height);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.translate(_width, _height);
canvas.rotate(-90);
TextPaint paint = getPaint();
paint.setColor(getTextColors().getDefaultColor());
String text = text();
paint.getTextBounds(text, 0, text.length(), _bounds);
canvas.drawText(text, getCompoundPaddingLeft(), (_bounds.height() - _width)/2, paint);
canvas.restore();
}
private String text() {
return super.getText().toString();
}
}
xml:
<VerticalTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:background="@color/feedback_background"
android:padding="4dip"
android:text="@string/feedback"
android:textColor="@color/feedback_text_color"
android:textSize="@dimen/text_xlarge" />
Bu büyük bir anlaşma olmadığını biliyorum, ama bir gün benim gibi bazı n00b bunu uygulamak ve bazı hatalar elde etmeye çalışın, sadece kullanmayı deneyin: '
Mükemmel çalışıyor. Teşekkürler! – Lancelot
-90 yerine 90 dereceye nasıl dönülür? – Dharmendra
Biz ayarlayabilirsiniz XML görünümüyle döndürme
<TextView android:id="@+id/txtview"
android:rotation="-90"
android:text="123"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
bu çalışır, ancak daha sonra UI düzenleyicisini kullanmak çok zor olur – Louis
Başka bir StackOverflow question'da bir çözüm sağladım. Görünümden genişleterek ve onMeasure()
ve onDraw()
yöntemlerini geçersiz kılarak dikey TextView alabilirsiniz. Ancak, tüm TextView özelliklerini desteklemez, bunun yerine dolgu, boyut, renk ve yazı tipi gibi ana özellikleri.
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class VerticalLabelView extends View
{
private final String LOG_TAG = "VerticalLabelView";
private final int DEFAULT_TEXT_SIZE = 30;
private int _ascent = 0;
private int _leftPadding = 0;
private int _topPadding = 0;
private int _rightPadding = 0;
private int _bottomPadding = 0;
private int _textSize = 0;
private int _measuredWidth;
private int _measuredHeight;
private Rect _textBounds;
private TextPaint _textPaint;
private String _text = "";
private TextView _tempView;
private Typeface _typeface = null;
private boolean _topToDown = false;
public VerticalLabelView(Context context)
{
super(context);
initLabelView();
}
public VerticalLabelView(Context context, AttributeSet attrs)
{
super(context, attrs);
initLabelView();
}
public VerticalLabelView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
initLabelView();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VerticalLabelView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
super(context, attrs, defStyleAttr, defStyleRes);
initLabelView();
}
private final void initLabelView()
{
this._textBounds = new Rect();
this._textPaint = new TextPaint();
this._textPaint.setAntiAlias(true);
this._textPaint.setTextAlign(Paint.Align.CENTER);
this._textPaint.setTextSize(DEFAULT_TEXT_SIZE);
this._textSize = DEFAULT_TEXT_SIZE;
}
public void setText(String text)
{
this._text = text;
requestLayout();
invalidate();
}
public void topToDown(boolean topToDown)
{
this._topToDown = topToDown;
}
public void setPadding(int padding)
{
setPadding(padding, padding, padding, padding);
}
public void setPadding(int left, int top, int right, int bottom)
{
this._leftPadding = left;
this._topPadding = top;
this._rightPadding = right;
this._bottomPadding = bottom;
requestLayout();
invalidate();
}
public void setTextSize(int size)
{
this._textSize = size;
this._textPaint.setTextSize(size);
requestLayout();
invalidate();
}
public void setTextColor(int color)
{
this._textPaint.setColor(color);
invalidate();
}
public void setTypeFace(Typeface typeface)
{
this._typeface = typeface;
this._textPaint.setTypeface(typeface);
requestLayout();
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
try
{
this._textPaint.getTextBounds(this._text, 0, this._text.length(), this._textBounds);
this._tempView = new TextView(getContext());
this._tempView.setPadding(this._leftPadding, this._topPadding, this._rightPadding, this._bottomPadding);
this._tempView.setText(this._text);
this._tempView.setTextSize(TypedValue.COMPLEX_UNIT_PX, this._textSize);
this._tempView.setTypeface(this._typeface);
this._tempView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this._measuredWidth = this._tempView.getMeasuredHeight();
this._measuredHeight = this._tempView.getMeasuredWidth();
this._ascent = this._textBounds.height()/2 + this._measuredWidth/2;
setMeasuredDimension(this._measuredWidth, this._measuredHeight);
}
catch (Exception e)
{
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
if (!this._text.isEmpty())
{
float textHorizontallyCenteredOriginX = this._measuredHeight/2f;
float textHorizontallyCenteredOriginY = this._ascent;
canvas.translate(textHorizontallyCenteredOriginY, textHorizontallyCenteredOriginX);
float rotateDegree = -90;
float y = 0;
if (this._topToDown)
{
rotateDegree = 90;
y = this._measuredWidth/2;
}
canvas.rotate(rotateDegree);
canvas.drawText(this._text, 0, y, this._textPaint);
}
}
}
- 1. Parlak: Dikey bir kaydırıcı yapmak mümkün mü?
- 2. Google Maps API v3'te özel metin yazmak mümkün mü?
- 3. XmlWriter ile belleğe XML yazmak mümkün mü?
- 4. Cython'da "saf" C++ sınıfı yazmak mümkün mü?
- 5. Konsol için uzatma yöntemleri yazmak mümkün mü?
- 6. Strut'u writer'dan write_csv() kullanarak yazmak mümkün mü?
- 7. html dosyasını pdf'ye dönüştürmek ve dikey olarak metin yazmak için itextsharp xmlworker öğesini kullanma
- 8. Birden çok dinamik pivot ile bir sorgu yazmak mümkün mü?
- 9. Bir İşletim Sistemini tamamen C'ye yazmak mümkün mü?
- 10. Perl foreach döngüsünü tek bir satırda yazmak mümkün mü?
- 11. Android'de youtube player görünümünde bindirme görünümünü yerleştirmek mümkün mü?
- 12. JavaFX'te bir düğme üzerinde metin dikey olarak nasıl görüntülenir?
- 13. Barchart'ları Flot'ta yatay olarak görüntülemek mümkün mü?
- 14. C# içinde Excel'de çalışacak ActiveX Denetimleri yazmak mümkün mü?
- 15. mümkün mü?
- 16. Bir resmi tuvalsiz olarak pikselleştirmek mümkün mü?
- 17. Dinamik olarak bir UITextView oluşturmak mümkün mü?
- 18. Bir nesneyi null olarak ayarlamak mümkün mü?
- 19. Okuma durumunu kapatmadan dosyaya yazmak mümkün mü? PHP
- 20. iOS'ta metin alanları dikey olarak eklenemiyor mu?
- 21. Hafta takviminde dikey olarak orta metin
- 22. Unix'te yapabildiğiniz gibi bir cmch dosyasını cmd olarak yazmak mümkün mü?
- 23. R'de aynaya çevrilmiş metin çizmek mümkün mü?
- 24. __rmod__ kullanarak str'nin% davranışının üzerine yazmak mümkün mü?
- 25. Desen eşlemeli işlevleri puntasız biçimde yazmak mümkün mü?
- 26. JavaScript kullanarak google sayfalarına veri yazmak mümkün mü?
- 27. Metin görünümünde farklı renklerde harfler var mı?
- 28. Bir html tablosunda sekme/odak sırasını değiştirmek mümkün mü, önce dikey ve sonra yatay olarak aktarılıyor?
- 29. Internet Explorer'da metin girişinde dikey olarak orta metin
- 30. Aynı Metin görünümünde sürükleme olaylarını ve tıklama etkinliğini kullanmak mümkün mü?
Artık XML bunu yapmak mümkündür: http://stackoverflow.com/questions/3774770/sideways-view-with-xml-android Evet Ben gerçi ama bu değil hakkında açıkladım – chobok