当前位置: 编程技术>移动开发
本页文章导读:
▪统制Activity在横屏切换时不刷新 控制Activity在横屏切换时不刷新
针对需要控制在屏幕横、纵屏幕切换时不需要刷新的Activity,在对应的AndroidManifest.xml文件中,增加如下配置:<activity android:name="org.huareal.game.fivechess.FiveChess.........
▪ UITableView和键盘滚动有关问题 UITableView和键盘滚动问题
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
obj.........
▪ Drawable、Bitmap、byte[]其间的转换(转) Drawable、Bitmap、byte[]之间的转换(转)
1、Drawable → Bitmappublic static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap
.createBitmap(
.........
[1]统制Activity在横屏切换时不刷新
来源: 互联网 发布时间: 2014-02-18
控制Activity在横屏切换时不刷新
针对需要控制在屏幕横、纵屏幕切换时不需要刷新的Activity,在对应的AndroidManifest.xml文件中,增加如下配置:
<activity android:name="org.huareal.game.fivechess.FiveChessGame" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|navigation" ></activity>
<activity android:name="GameCategary"></activity>
比如两个Activity,第一个org.huareal.game.fivechess.FiveChessGame 希望屏幕默认显示为portait方式,在切换屏幕时不会刷新
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|navigation"
注意:如果只填写android:configChanges,在模拟器上测试正常,但是在真机测试不正常,所以第一项android:screenOrientation必须配置
针对需要控制在屏幕横、纵屏幕切换时不需要刷新的Activity,在对应的AndroidManifest.xml文件中,增加如下配置:
<activity android:name="org.huareal.game.fivechess.FiveChessGame" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|navigation" ></activity>
<activity android:name="GameCategary"></activity>
比如两个Activity,第一个org.huareal.game.fivechess.FiveChessGame 希望屏幕默认显示为portait方式,在切换屏幕时不会刷新
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|navigation"
注意:如果只填写android:configChanges,在模拟器上测试正常,但是在真机测试不正常,所以第一项android:screenOrientation必须配置
[2] UITableView和键盘滚动有关问题
来源: 互联网 发布时间: 2014-02-18
UITableView和键盘滚动问题
- (void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
-(void) keyboardWillShow:(NSNotification *)note { NSDictionary *info = [note userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; CGRect bkgndRect = self.ncTableView.frame; bkgndRect.size.height += kbSize.height; self.ncTableView.contentSize = bkgndRect.size; // CGFloat tmpY=activeField.frame.origin.y-((self.view.frame.size.height-kbSize.height)-activeField.frame.size.height-8); // if(tmpY>0){ // [self.scrollView setContentOffset:CGPointMake(0.0, tmpY) animated:YES]; // } } - (void)keyboardWillHide:(NSNotification*)aNotification{ NSTimeInterval animationDuration=0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; NSDictionary *info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; CGRect bkgndRect = self.ncTableView.frame; bkgndRect.size.height -= kbSize.height; //NIF_DEBUG(@"kbSize x:%f %f",kbSize.height,kbSize.width); self.ncTableView.contentSize = bkgndRect.size; [UIView commitAnimations]; //[self.scrollView setContentOffset:CGPointMake(0.0, activeField.frame.origin.y - 15) animated:YES]; //CGFloat tmpY=activeField.frame.origin.y-((self.view.frame.size.height-kbSize.height)-activeField.frame.size.height-8); }
[3] Drawable、Bitmap、byte[]其间的转换(转)
来源: 互联网 发布时间: 2014-02-18
Drawable、Bitmap、byte[]之间的转换(转)
1、Drawable → Bitmap
//简单方法
2、从资源中获取Bitmap
3、Bitmap → byte[]
4、 byte[] → Bitmap
5. Bitmap → Drawable 的简单方法
1、Drawable → Bitmap
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); //canvas.setBitmap(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
//简单方法
((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();
2、从资源中获取Bitmap
Resources res=getResources(); Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);
3、Bitmap → byte[]
private byte[] Bitmap2Bytes(Bitmap bm){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
4、 byte[] → Bitmap
private Bitmap Bytes2Bimap(byte[] b){ if(b.length!=0){ return BitmapFactory.decodeByteArray(b, 0, b.length); } else { return null; } }
5. Bitmap → Drawable 的简单方法
BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap; Drawable drawable = (Drawable)bitmapDrawable; Bitmap bitmap = new Bitmap (...); Drawable drawable = new BitmapDrawable(bitmap);
最新技术文章: