当前位置:  编程技术>移动开发
本页文章导读:
    ▪[转帖]自动调整TextView字体大小以顺应文字长度        [转帖]自动调整TextView字体大小以适应文字长度 抱歉,具体出处忘记了 package com.test.android.textview; import android.content.Context; import android.graphics.Paint; import android.util.AttributeSet; import android.widge.........
    ▪ 画夹使用        画板使用 Painting.h#import <UIKit/UIKit.h> //CONSTANTS: #define kRubberWidth 20 #define kBrushLineAlpha 1.0 #define kPaintViewBackGroudImg @"背景.png" @interface Painting : UIView { UIImageView *drawImage;.........
    ▪ Andorid上進行Log 記錄       Andorid下進行Log 記錄 詳細見http://developer.android.com/reference/android/util/Log.htmlsimple example:private static final String TAG = "MyActivity";Log.v(TAG, "index=" + i); ......

[1][转帖]自动调整TextView字体大小以顺应文字长度
    来源: 互联网  发布时间: 2014-02-18
[转帖]自动调整TextView字体大小以适应文字长度
抱歉,具体出处忘记了

package com.test.android.textview;

import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class CustomTextView extends TextView {

	private static float DEFAULT_MIN_TEXT_SIZE = 10;
	private static float DEFAULT_MAX_TEXT_SIZE = 20;

	// Attributes
	private Paint testPaint;
	private float minTextSize, maxTextSize;

	public CustomTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initialise();
	}

	private void initialise() {
		testPaint = new Paint();
		testPaint.set(this.getPaint());

		// max size defaults to the intially specified text size unless it is
		// too small
		maxTextSize = this.getTextSize();

		if (maxTextSize <= DEFAULT_MIN_TEXT_SIZE) {
			maxTextSize = DEFAULT_MAX_TEXT_SIZE;
		}

		minTextSize = DEFAULT_MIN_TEXT_SIZE;
	};

	/**
	 * Re size the font so the specified text fits in the text box * assuming
	 * the text box is the specified width.
	 */
	private void refitText(String text, int textWidth) {
		if (textWidth > 0) {
			int availableWidth = textWidth - this.getPaddingLeft()
					- this.getPaddingRight();
			float trySize = maxTextSize;
			testPaint.setTextSize(trySize);
			while ((trySize > minTextSize)
					&& (testPaint.measureText(text) > availableWidth)) {
				trySize -= 1;
				if (trySize <= minTextSize) {
					trySize = minTextSize;
					break;
				}
				testPaint.setTextSize(trySize);
			}
			this.setTextSize(trySize);
		}
	};

	@Override
	protected void onTextChanged(CharSequence text, int start, int before,
			int after) {
		super.onTextChanged(text, start, before, after);
		refitText(text.toString(), this.getWidth());
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		if (w != oldw) {
			refitText(this.getText().toString(), w);
		}
	}
}

    
[2] 画夹使用
    来源: 互联网  发布时间: 2014-02-18
画板使用
Painting.h
#import <UIKit/UIKit.h>

//CONSTANTS:

#define kRubberWidth              20
#define kBrushLineAlpha           1.0
#define kPaintViewBackGroudImg    @"背景.png"

@interface Painting : UIView {
	UIImageView *drawImage;
	int mouseMoved;
	BOOL mouseSwiped;
	BOOL isRubber;
	CGPoint lastPoint;
	CGFloat kBrushRGBColorRed;
	CGFloat kBrushRGBColorGreen;
	CGFloat  kBrushRGBColorBlue;
	CGFloat  kBrushLineWidth;

}
@property(nonatomic, readwrite) BOOL isRubber;
@property(nonatomic, readwrite) CGFloat  kBrushLineWidth;
- (void)clear;
- (void)save;
//- (void)changRGBColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue;
- (void)setBrushColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue;
@end


Painting.m
#import "Painting.h"
#import <QuartzCore/QuartzCore.h>

@implementation Painting
@synthesize isRubber;
@synthesize kBrushLineWidth;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
	   
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
	drawImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kPaintViewBackGroudImg]];
	drawImage.frame = self.frame;
	[self addSubview:backGroudImage];
	[self addSubview:drawImage];
	mouseMoved = 0;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	mouseSwiped = NO;
	UITouch *touch = [touches anyObject];
	
	//双击清空
	//if ([touch tapCount] == 2) {
	//	[self clear];
	//}
	lastPoint = [touch locationInView:self];
	//lastPoint.y -= 20;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	mouseSwiped = YES;
	UITouch *touch = [touches anyObject];        
	CGPoint currentPoint = [touch locationInView:self];
	//currentPoint.y -= 20; // only for 'kCGLineCapRound'
	UIGraphicsBeginImageContext(self.frame.size);
	//Albert Renshaw - Apps4Life
	[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];

	CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
	CGContextSetLineWidth(UIGraphicsGetCurrentContext(), kBrushLineWidth); // for size 线条宽度
	CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), kBrushRGBColorRed, kBrushRGBColorGreen, kBrushRGBColorBlue, kBrushLineAlpha); //values for R, G, B, and Alpha
	

	//CGContextSetLineJoin(UIGraphicsGetCurrentContext() , kCGLineJoinRound );
	if (isRubber) {
		CGContextSetLineWidth(UIGraphicsGetCurrentContext(), kRubberWidth); // for size 线条宽度
		CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);//混合模式
//		CGContextClearRect(UIGraphicsGetCurrentContext(),CGRectMake(currentPoint.x - kRubberWidth/2, currentPoint.y - kRubberWidth/2,kRubberWidth,kRubberWidth));
	}
//	else {
//		CGContextBeginPath(UIGraphicsGetCurrentContext());
//		CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
//		CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
//	}
	CGContextBeginPath(UIGraphicsGetCurrentContext());
	CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
	CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
	

	CGContextStrokePath(UIGraphicsGetCurrentContext());
	drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	
	lastPoint = currentPoint;
	mouseMoved++;
	
	if (mouseMoved == 10) {
		mouseMoved = 0;
	}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	//UITouch *touch = [touches anyObject];
	//双击清空
	//if ([touch tapCount] == 2) {
	//	[self clear];
	//}
	if(!mouseSwiped) {
		
		UIGraphicsBeginImageContext(self.frame.size);
		[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
		CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
		CGContextSetLineWidth(UIGraphicsGetCurrentContext(), kBrushLineWidth); 
		CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), kBrushRGBColorRed, kBrushRGBColorGreen, kBrushRGBColorBlue, kBrushLineAlpha);
		//CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
		if (isRubber) {
			CGContextClearRect(UIGraphicsGetCurrentContext(),CGRectMake(lastPoint.x - kRubberWidth/2, lastPoint.y - kRubberWidth/2,kRubberWidth,kRubberWidth));
		}else {
			CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
			CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
		}
		
		CGContextStrokePath(UIGraphicsGetCurrentContext());
		CGContextFlush(UIGraphicsGetCurrentContext());
		drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
		UIGraphicsEndImageContext();
	}
}



- (void) clear{
    [drawImage setImage:[UIImage imageNamed:kPaintViewBackGroudImg]];
}

- (void)save{
	UIGraphicsBeginImageContext(self.bounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
	//UIImage *viewImage = [UIImage imageNamed:@"pink2.png"]; 
	UIGraphicsEndImageContext();
	if (viewImage != nil) {
		
		UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存完毕"
														message:@"保存到图片浏览目录中" 
													   delegate:nil
											  cancelButtonTitle:@"关闭"
											  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
}

- (void)setBrushColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue
{
	kBrushRGBColorRed = red;
	kBrushRGBColorGreen = green;
	kBrushRGBColorBlue = blue;
}

- (void)dealloc {
    [super dealloc];
}
@end




    
[3] Andorid上進行Log 記錄
    来源: 互联网  发布时间: 2014-02-18
Andorid下進行Log 記錄
詳細見
http://developer.android.com/reference/android/util/Log.html

simple example:

private static final String TAG = "MyActivity";

Log.v(TAG, "index=" + i);

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android Touch事件分发过程详解 iis7站长之家
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3