• 实现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>
     
     
  • 相关阅读:
    js里面的 InttoStr 和 StrtoInt
    预编译知识 (转载记录)
    C语言操作内存
    C语言操作文件
    C语言
    如何调试shell脚本
    设计模式-装饰者模式
    自己动手制作一个模版解析
    设计模式-单例模式
    http中关于缓存的那些header信息
  • 原文地址:https://www.cnblogs.com/baiyi168/p/5982140.html
Copyright © 2020-2023  润新知