首页 文章 精选 留言 我的

精选列表

搜索[内容显示],共10008篇文章
优秀的个人博客,低调大师

[Android]只显示月和日的DatePickerDialog

正文 一、效果图 1.1 默认 1.2 处理后 二、实现代码 2.1 代码片段1 /** *从当前Dialog中查找DatePicker子控件 * *@paramgroup *@return */ privateDatePickerfindDatePicker(ViewGroupgroup){ if(group!=null){ for(inti=0,j=group.getChildCount();i<j;i++){ Viewchild=group.getChildAt(i); if(childinstanceofDatePicker){ return(DatePicker)child; }elseif(childinstanceofViewGroup){ DatePickerresult=findDatePicker((ViewGroup)child); if(result!=null) returnresult; } } } returnnull; } 代码说明: 通过断点也看到Dialog的ContentView里有DatePicker子控件,这里通过遍历的办法来查找这个控件。 2.2 使用代码 finalCalendarcal=Calendar.getInstance(); mDialog=newCustomerDatePickerDialog(getContext(),this, cal.get(Calendar.YEAR),cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); mDialog.show(); DatePickerdp=findDatePicker((ViewGroup)mDialog.getWindow().getDecorView()); if(dp!=null){ ((ViewGroup)dp.getChildAt(0)).getChildAt(0).setVisibility(View.GONE); } 代码说明: 通过源码可以看得到DatePicker内置三个NumberPicker控件,依次表示年、月、日,隐藏掉第一个即可。 三、补充 后续使用中发现标题栏也要改,通过查看DatePickerDialog源码,需要自定义并实现onDateChanged方法才可实现,如下代码: classCustomerDatePickerDialogextendsDatePickerDialog{ publicCustomerDatePickerDialog(Contextcontext, OnDateSetListenercallBack,intyear,intmonthOfYear, intdayOfMonth){ super(context,callBack,year,monthOfYear,dayOfMonth); } @Override publicvoidonDateChanged(DatePickerview,intyear,intmonth,intday){ super.onDateChanged(view,year,month,day); mDialog.setTitle((month+1)+"月"+day+"日"); } } 本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/669257,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS实现图片的缩放和居中显示

直接上代码 // //MoveScaleImageController.h //MoveScaleImage // //Created byon 12-4-24. //Copyright (c) 2012年__MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> #import "MoveScaleImageView.h" @interface MoveScaleImageController: UIViewController<UIScrollViewDelegate>{ UIScrollView *myScrollView; UIImageView *myImageView; } @property(retain,nonatomic)UIScrollView *myScrollView; @property(retain,nonatomic)UIImageView *myImageView; @end // //MoveScaleImageController.m //MoveScaleImage // //Created byon 12-4-24. //Copyright (c) 2012年__MyCompanyName__. All rights reserved. // #import "MoveScaleImageController.h" @interface MoveScaleImageController() @end @implementation MoveScaleImageController @synthesize myScrollView; @synthesize myImageView; -(void)dealloc{ [myScrollView release]; [myImageView release]; [super dealloc]; } -(void)loadView{ [super loadView]; self.view.backgroundColor = [UIColor lightGrayColor]; //UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(110, 200, 100, 50)]; //[btn setFrame:CGRectMake(110, 200, 100, 40)]; [btn setBackgroundColor:[UIColor whiteColor]]; [btn setTitle:@"点击查看图片" forState:UIControlStateNormal]; [btn.titleLabel setFont:[UIFont systemFontOfSize:13]]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; [btn release]; //下面是我要剪切区域的覆盖层 //if(self.centerOverLayView==nil) //{ //UIView *centerView=[[UIView alloc] initWithFrame:CGRectMake(20, 100, 280, 210)]; //self.centerOverLayView=centerView; //[centerView release]; //} //self.centerOverLayView.backgroundColor=[UIColor clearColor]; //self.centerOverLayView.layer.borderColor=[UIColor orangeColor].CGColor; //self.centerOverLayView.layer.borderWidth=2.0; //[self.view addSubview:self.centerOverLayView]; } -(void)clickEvent:(id)sender{ NSLog(@"***********clickeventad"); myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; if(self.myScrollView==nil) { UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; self.myScrollView=scrollView; [scrollView release]; } self.myScrollView.backgroundColor=[UIColor blueColor]; self.myScrollView.delegate=self; self.myScrollView.multipleTouchEnabled=YES; self.myScrollView.minimumZoomScale=1.0; self.myScrollView.maximumZoomScale=10.0; [self.view addSubview:self.myScrollView]; UIImage *_image = [UIImage imageNamed:@"image.jpg"]; CGFloat imageView_X = (_image.size.width > self.view.frame.size.width) ? self.view.frame.size.width : _image.size.width; CGFloat imageView_Y; CGFloat origin; if(_image.size.width > self.view.frame.size.width){ origin = self.view.frame.size.width/_image.size.width; imageView_Y = _image.size.height*origin; } myImageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-imageView_X)/2, (self.view.frame.size.height-imageView_Y)/2, imageView_X, imageView_Y)]; if(self.myImageView==nil) { UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; self.myImageView=imageView; [imageView release]; } //[myImageView setImage:_image]; UIImage *originImage=[[UIImage alloc]initWithCGImage:_image.CGImage]; [myImageView setImage:originImage]; //[myImageView setFrame:CGRectMake(0, 0, _image.size.width, _image.size.height)]; [self.myScrollView addSubview:self.myImageView]; UIButton *closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 50, 50)]; [closeBtn setBackgroundColor:[UIColor redColor]]; [closeBtn setAlpha:0.5]; [closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:closeBtn]; [closeBtn release]; //UIView *backView = [[UIView alloc] initWithFrame:CGRectInset(self.view.frame, 5, 5)]; //backView.alpha = 0.5; //backView.backgroundColor = [UIColor blackColor]; ////[self.view addSubview:backView]; // //UIImage* image=[UIImage imageNamed:@"image.jpg"]; //MoveScaleImageView*fileContent = [[MoveScaleImageView alloc]initWithFrame:CGRectMake(0, 44, 320, 436)]; //[fileContent setImage:image]; // ////[backView addSubview:fileContent]; //[self.view addSubview:fileContent]; // //[backView release]; //[fileContent release]; } -(void)closeEvent:(id)sender{ [self.myImageView setHidden:YES]; [self.myScrollView setHidden:YES]; } #pragma mark UIScrollView delegate methods //实现图片的缩放 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ NSLog(@"**************viewForZoomingInScrollView"); return self.myImageView; } //实现图片在缩放过程中居中 - (void)scrollViewDidZoom:(UIScrollView *)scrollView { CGFloat offsetX = (scrollView.bounds.size.width > scrollView.contentSize.width)?(scrollView.bounds.size.width - scrollView.contentSize.width)/2 : 0.0; CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?(scrollView.bounds.size.height - scrollView.contentSize.height)/2 : 0.0; self.myImageView.center = CGPointMake(scrollView.contentSize.width/2 + offsetX,scrollView.contentSize.height/2 + offsetY); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1772523,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android 解决 Toolbar 的 Menu 图标无法显示

menu代码如下 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@id/itemSearch_menu_main" android:icon="@mipmap/ic_search" app:showAsAction="ifRoom" android:title="搜索"/> <item android:id="@id/itemMore_menu_main" android:icon="@mipmap/ic_add" app:showAsAction="ifRoom" android:title="更多"/> </menu> 效果如图: 图1.png 将代码修改,如下: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@id/itemSearch_menu_main" android:icon="@mipmap/ic_search" app:showAsAction="ifRoom" android:title="搜索" android:showAsAction="always" tools:ignore="AppCompatResource" /> <item android:id="@id/itemMore_menu_main" android:icon="@mipmap/ic_add" app:showAsAction="ifRoom" android:title="更多" android:showAsAction="always" tools:ignore="AppCompatResource" /> </menu> 即在每个item节点中添加 android:showAsAction="always" tools:ignore="AppCompatResource" 效果图如下: 图2.png

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册