实现textview竖排文字效果

时间:2023-02-11 10:46:59

文字效果

实现textview竖排文字效果

/**
* @描述
* @作者 tll
* @时间 2016/10/20
*/
public class VerticalTextView extends LinearLayout {
private LinearLayout llLayout;
private TextView textView;

public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
color = getResources().getColor(R.color.white);
View view = LayoutInflater.from(context).inflate(R.layout.vertical_text_view, this, true);
llLayout = (LinearLayout) view.findViewById(R.id.llLayout);
textView = (TextView) view.findViewById(R.id.textView);
}

private String text;
private Context context;
private int color;
private int size = 20;

public VerticalTextView(Context context) {
super(context);
this.context = context;
}


public void setText(String text) {
this.text = text;
textView.setText(text);
}

public void setTextColor(int color) {
this.color = color;
textView.setTextColor(color);
}

public void setTextSize(int size) {
this.size = size;
textView.setTextSize(size);
}

/**
* 设置背景
*/
public void setBackground(int resId) {
llLayout.setBackgroundResource(resId);
}
}

vertical_text_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_back"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:gravity="center_horizontal"
android:maxWidth="25dp"
android:textSize="18sp"
android:text="热门推荐"/>

</LinearLayout>