我是靠谱客的博主 魔幻砖头,这篇文章主要介绍旋转的TextView-RotateTextView,现在分享给大家,希望可以做个参考。

参考:微商软件

attrs.xml添加三个自定义属性:


<attr name="degree" format="integer" />
<attr name="transX" format="dimension" />
<attr name="transY" format="dimension" />
RotateTextView.java

public class RotateTextView extends TextView {
private static final int[] textDegree = new int[]{R.attr.degree, R.attr.transX, R.attr.transY};
private int degree;
private int transX;
private int transY;
public RotateTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs, textDegree);
degree = ta.getInteger(0, 0);
transX = ta.getDimensionPixelSize(1, 0);
transY = ta.getDimensionPixelSize(2, 0);
ta.recycle();
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(degree, getMeasuredWidth() / 2, getMeasuredHeight() / 2);
canvas.translate(transX, transY);
super.onDraw(canvas);
canvas.restore();
}
}


调用示例:

<com.koudai.weishop.view.RotateTextView
xmlns:app="http://schemas.android.com/apk/res/com.koudai.weishop"
android:textSize="10.0sp"
android:textStyle="bold"
android:textColor="@color/wd_color_303"
android:gravity="center"
android:id="@id/order_status"
android:background="@drawable/ic_kdwd_order_status_bg"
android:layout_width="54.0dip"
android:layout_height="54.0dip"
android:text=""
android:layout_alignTop="@id/item_layout"
android:layout_alignRight="@id/item_layout"
app:degree="45"
app:transY="-12.0dip" />


效果:





最后

以上就是魔幻砖头最近收集整理的关于旋转的TextView-RotateTextView的全部内容,更多相关旋转内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部