自定義帶邊框的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
//下面用圖介紹邊框的繪製
this.getwidth,this.getheight
0,this.getheight
this.getwidth()-1,0
0,0
邊框的繪製
然後只需要在布局裡呼叫這個就行
<?xml version="1.0" encoding="utf-8"?>
""android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="30dp"
android:text="hello"
android:textcolor="#cccccc" >
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" >
效果圖:
android開發之自定義dialog
很多時候,系統生成的dialog無法滿足我們的需求,這個時候,我們就只能自己去自定義乙個dialog來滿足自己的需要了。設定dialog 雙按鈕 private void showdialog string str1,string str2 確定按鈕 button btnok button layo...
Android開發之自定義動畫
android開發之動畫 北京android俱樂部群 167839253 created on 2011 8 23 author blueeagle email liujiaxiang gmail.com 總結一下關於android開發下的自定義動畫,主要是四個方面,尺寸,透明度,位置變化和旋轉。動...
Android 開發之自定義控制項開發 02
1.setcolor 該函式的作用是設定畫筆顏色,完整的函式宣告如下 void setcolor int color 我們知道,一種顏色是由紅 綠 藍三色合成出來的,所以引數 color 只能取8位的0xaarrggbb樣式顏色值。其中 2.setstyle viod setstyle style ...