android开发之自定义带边框的TextView
来源:互联网 发布:asp.net 获取域名 编辑:程序博客网 时间:2024/06/05 18:03
自定义带边框的TextView
///////////////////////Activity///////////////////////////////
package cn.class3g.activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class MyBorderTextView extends TextView{
public MyBorderTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.YELLOW);
canvas.drawLine(0, 0, this.getWidth()-1, 0, paint);
//1、横坐标0到this.getWidth()-1,纵坐标0到0
canvas.drawLine(0, 0, 0, this.getHeight()-1, paint);
//2、横坐标0到0,纵坐标0到this.getHeight()-1
canvas.drawLine(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1, paint);
//3、横坐标this.getWidth()-1到this.getWidth()-1,纵坐标0到this.getHeight()-1
canvas.drawLine(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1, paint);
//4、横坐标0到this.getWidth()-1,纵坐标this.getHeight()-1到this.getHeight()-1
//下面用图介绍边框的绘制
}
}
1
this.getWidth,this.getHeight
0,this.getHeight
this.getWidth()-1,0
0,0
3
4
2
然后只需要在布局里调用这个就行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<cn.class3g.activity.MyBorderTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="30dp"
android:text="hello"
android:textColor="#cccccc" >
</cn.class3g.activity.MyBorderTextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="30dp"
android:text="hello hello hello hello"
android:background="@drawable/ic_launcher"
android:textColor="#cccccc" >
</TextView>
</LinearLayout>
效果图:
- android开发之自定义带边框的TextView
- android开发之自定义带边框的TextView
- android开发之自定义带边框的TextView
- Android自定义控件 -- 带边框的TextView
- Android UI设计之<四>自定义TextView属性,实现带边框效果的TextView
- 带进度边框的自定义TextView
- Android开发 自定义控件 边框TextView
- 带边框的TextView
- 带边框的TextView
- Android: TextView with border 带边框的TextView
- Android: TextView with border 带边框的TextView Border
- (转)自定义Android组件之带图像的TextView
- 自定义Android组件之带图像的TextView
- 自定义Android组件之带图像的TextView
- 自定义Android组件之带图像的TextView
- 自定义Android组件之带图像的TextView
- 自定义TextView之 给你的TextView添加边框
- 带边框的文本框TextView
- 仿htc布局
- 当启动应用中出现“Jboss端口已经启动了”
- 基于mini2440的ucgui图形库移植
- linux系统启动过程
- java写的简易贪吃蛇游戏
- android开发之自定义带边框的TextView
- Spring-quartz中cronExpression配置说明
- android开发之EditText组件
- Java 获取客户端代码大全
- 用WINDBG看了一下QvodTerminal
- Div+CSS常见的十种错误总结
- asmlinkage
- [USACO 1.5.2] Prime Palindromes
- sqlplus 启动不了,提示sp2-0750