首页 文章 精选 留言 我的

精选列表

搜索[UI设计],共10000篇文章
优秀的个人博客,低调大师

Android UI-底部旋转菜单栏

以前都是说每逢佳节倍思亲,现在的工作状态是每到周末倍亲切,年底真的是加班加的没完没了的,也没时间写博客,也没时间学习,周末闲来无事看到一个比较有意思的旋转菜单,没事自己实战了一下感觉还不错,代码倒是没什么,主要是有两个技术点,一个就是布局文件,第二个就是动画旋转,关于布局文件是仁者见仁智者见智,只能自己研究,动画的话之前写过这方面的文章有兴趣的可以看下本人之前的博客,开始正题吧: 基础布局 先看下要实现的效果吧: 下面的主要是三个图片,一个半圆,两个版圆环,最外面的是三级菜单,中间的是二级菜单; 一级菜单布局: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <RelativeLayout android:id= "@+id/menuFirst" android:layout_width= "100dp" android:layout_height= "50dp" android:layout_alignParentBottom= "true" android:layout_centerHorizontal= "true" android:background= "@drawable/menu1" > <ImageView android:id= "@+id/icon_home" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_centerInParent= "true" android:background= "@drawable/icon_home" /> </RelativeLayout> 二级菜单布局: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <RelativeLayout android:id= "@+id/menuSecond" android:layout_width= "170dp" android:layout_height= "90dp" android:layout_alignParentBottom= "true" android:layout_centerHorizontal= "true" android:background= "@drawable/menu2" > <ImageView android:id= "@+id/icon_search" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentBottom= "true" android:layout_margin= "8dp" android:background= "@drawable/icon_search" /> <ImageView android:id= "@+id/icon_menu" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_centerHorizontal= "true" android:layout_marginTop= "5dp" android:background= "@drawable/icon_menu" /> <ImageView android:id= "@+id/icon_center" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentBottom= "true" android:layout_alignParentRight= "true" android:layout_margin= "8dp" android:background= "@drawable/icon_center" /> </RelativeLayout> 三级菜单布局,这个布局的时候需要注意的是左边的三个图片设置完之后,设置的是对称方向的最底部的一个图片,以此为依据搞定其他两个图标: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 <RelativeLayout android:id= "@+id/menuThird" android:layout_width= "270dp" android:layout_height= "140dp" android:layout_alignParentBottom= "true" android:layout_centerHorizontal= "true" android:background= "@drawable/menu3" > <ImageView android:id= "@+id/channel1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentBottom= "true" android:layout_marginBottom= "8dp" android:layout_marginLeft= "8dp" android:background= "@drawable/channel1" /> <ImageView android:id= "@+id/channel2" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_above= "@id/channel1" android:layout_alignLeft= "@id/channel1" android:layout_marginBottom= "8dp" android:layout_marginLeft= "16dp" android:background= "@drawable/channel2" /> <ImageView android:id= "@+id/channel3" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_above= "@id/channel2" android:layout_alignLeft= "@id/channel2" android:layout_marginBottom= "8dp" android:layout_marginLeft= "30dp" android:background= "@drawable/channel3" /> <ImageView android:id= "@+id/channel4" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_centerHorizontal= "true" android:layout_marginTop= "5dp" android:background= "@drawable/channel4" /> <ImageView android:id= "@+id/channel7" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentBottom= "true" android:layout_alignParentRight= "true" android:layout_marginBottom= "8dp" android:layout_marginRight= "8dp" android:background= "@drawable/channel7" /> <ImageView android:id= "@+id/channel6" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_above= "@id/channel7" android:layout_alignRight= "@id/channel7" android:layout_marginBottom= "8dp" android:layout_marginRight= "20dp" android:background= "@drawable/channel6" /> <ImageView android:id= "@+id/channel5" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_above= "@id/channel6" android:layout_alignRight= "@id/channel6" android:layout_marginBottom= "8dp" android:layout_marginRight= "30dp" android:background= "@drawable/channel5" /> </RelativeLayout> 实现Demo 主要实现的主要就是两个按钮,一个按钮式最底层的按钮,一个是二级菜单的按钮: 1 2 3 4 5 6 7 homeView = (ImageView) findViewById(R.id.icon_home); menuView = (ImageView) findViewById(R.id.icon_menu); menuFirst = (RelativeLayout) findViewById(R.id.menuFirst); menuSecond = (RelativeLayout) findViewById(R.id.menuSecond); menuThird = (RelativeLayout) findViewById(R.id.menuThird); homeView.setOnClickListener( this ); menuView.setOnClickListener( this ); 两个按钮的点击事件: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.icon_home: if (isSecond) { MyHelper.StartAninationOut(menuSecond, 500 , 200 ); if (isThird) { MyHelper.StartAninationOut(menuThird, 500 , 300 ); isThird= false ; } } else { MyHelper.StartAninationIn(menuSecond, 500 , 300 ); } isSecond=!isSecond; break ; case R.id.icon_menu: if (isThird) { MyHelper.StartAninationOut(menuThird, 500 , 200 ); isThird= false ; } else { MyHelper.StartAninationIn(menuThird, 500 , 200 ); isThird= true ; } break ; default : break ; } } 两个按钮都有点击点击事件,封装一个可以主要就是淡入和淡出的效果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class MyHelper { public static void StartAninationIn(RelativeLayout layout, long duratoin, long offset) { // TODO Auto-generated method stub RotateAnimation rotateAnimation= new RotateAnimation( 180 , 360 , layout.getWidth()/ 2 , layout.getHeight()); rotateAnimation.setDuration(duratoin); rotateAnimation.setFillAfter( true ); //保持旋转之后的状态 rotateAnimation.setStartOffset(offset); //延迟加载时间 layout.startAnimation(rotateAnimation); } public static void StartAninationOut(RelativeLayout layout, long duratoin, long offset) { // TODO Auto-generated method stub RotateAnimation rotateAnimation= new RotateAnimation( 0 , 180 , layout.getWidth()/ 2 , layout.getHeight()); rotateAnimation.setDuration(duratoin); rotateAnimation.setFillAfter( true ); rotateAnimation.setStartOffset(offset); layout.startAnimation(rotateAnimation); } } 最后看下效果图: 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4162283.html,如需转载请自行联系原作者

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

Android优化——UI优化(五) Listview 重用convertView

1.重用convertView 我们对convertView添加判断,如果存在我们就直接使用,否则初始化一个convertView的实例。(如下图) 2.使用viewHolder 使用viewHolder并且是一个静态的匿名内部类。(如下图) 3.在列表里面有图片的情况下,监听滑动不加载图片 1.可以查看一下我的这篇文章Listview 2.这个建议用一些图片请求框架,如:Android-Universal-Image-Loader,推荐个中文解析的网站http://codekk.com/ 4.多个不同布局,可以创建不同的viewHolder和convertView进行重用 比如聊天:左边一个布局,右边一个布局,我们可以创建不同的viewHolder,并且对convertView进行判断每个不同的convertView只初始化一次。 本文转自 一点点征服 博客园博客,原文链接: http://www.cnblogs.com/ldq2016/p/5226687.html ,如需转载请自行联系原作者

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

如何让Android UI使用更快更高效

之前有谈过如何使用adapter更高效的,现在在谈谈其他的。 一、选择恰当的图像尺寸 视图背景图总是会填充整个视图区域,图像尺寸的不适合会导致图像的自动缩放,为了避免这种情况,我们可以先将图片进行缩放到视图的大小。 originalImage = Bitmap.createScaledBitmap( originalImage, //被缩放图 view.getWidth(), //视图宽度 view.getHright(), //视图高度 true //双限行过滤器 ); 二、去掉不需要的默认窗口背景 在默认情况下,窗口有一个不透明的背景,有时候我们并不需要他,就可以去掉他。因为更新看不见的窗口是浪费时间的。 去掉的方法: 1.代码实现: @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); //删除窗口背景 getWindow().setBackgroundDrawable(null); } 2.xml里实现: 首先去顶你的res/xml/styles.xml里有 <resources> <style name="NoBackGroundTheme" parent="android:Theme"> <item name="android:windowBackground">@null</item> </style> </resources> 然后在你的manifest.xml里声明 <activity android:name="MyActivity" android:theme="@style/NoBackGroundTheme"> ...... </activity> 三、尽可能的使用简单的布局和视图 如果一个窗口包含很多的视图,那么启动时间长、测量时间长、绘制时间长、布局时间长; 如果视图树深度太深,会导致StackOverflowException异常,和用户界面反映会很慢很慢。 解决的方法: 1.使用TextView的复合drawables,减少层次 如有这样的布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Image android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/image" android:background="@drawable/icon" /> </LinearLayout> 我们可以这样来取代他,从而来将少层次: <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:drawableRight="@drawable/icon"/> 2.使用ViewStub延迟展开视图 默认情况下,使用ViewStub包含的视图是不可见的。 <ViewStub android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/vs" android:layout="@layout/main"/> 这个里面包含的main视图是不会展现出来的,如果需要展现出来需要代码的处理 findViewById(R.id.vs).setVisibility(View.VISIBLE); 或者 findViewById(R.id.vs).inflate(); 3.使用合并视图 默认情况下,布局文件的根作为一个借点加入到父视图中,如果使用可以避免根节点。 如果最外层的布局是FrameLayout,那么可以使用merge替换掉,引用官方说明: Obviously, using works in this case because the parent of an activity's content view is always a FrameLayout. You could not apply this trick if your layout was using a LinearLayout as its root tag for instance. <merge xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> ..... </merge> 4.使用RelativeLayout减少层次 5.自定义布局 本文转自 wws5201985 51CTO博客,原文链接:http://blog.51cto.com/wws5201985/760990,如需转载请自行联系原作者

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

Android UI学习 - Tab的学习和使用

本文是参考Android官方提供的sample里面的ApiDemos的学习总结。 TabActivity 首先Android里面有个名为TabActivity来给我们方便使用。其中有以下可以关注的函数 public TabHost getTabHost ()获得当前TabActivity的TabHost public TabWidget getTabWidget ()获得当前TabActivity的TabWidget public void setDefaultTab (String tag)这两个函数很易懂就是设置默认的Tab public void setDefaultTab (int index)通过tab名——tag或者index(从0开始) protected void onRestoreInstanceState (Bundle state)这两个函数的介绍可以 protected void onSaveInstanceState (Bundle outState)参考 Activity的生命周期 TabHost 那么我们要用到的Tab载体是TabHost需要从TabActivity.getTabHost获取。 现在看看TabHost类它有3个内嵌类1个类TabHost.TabSpec2个接口TabHost.TabContentFactory和TabHost.OnTabChangeListener。后面会介绍这些类和接口。 TabHost类的一些函数 public void addTab (TabHost.TabSpec tabSpec)添加tab参数TabHost.TabSpec通过下面的函数返回得到 public TabHost.TabSpec newTabSpec (String tag)创建TabHost.TabSpec public void clearAllTabs ()remove所有的Tabs public int getCurrentTab () public String getCurrentTabTag () public View getCurrentTabView () public View getCurrentView () public FrameLayout getTabContentView ()返回Tab content的FrameLayout public TabWidget getTabWidget () public void setCurrentTab (int index) 设置当前的Tab by index public void setCurrentTabByTag (String tag)设置当前的Tab by tag public void setOnTabChangedListener (TabHost.OnTabChangeListener l)设置TabChanged事件的响应处理 public void setup ()这个函数后面介绍 TabHost.TabSpec 从上面的函数可以知道如何添加tab了要注意这里的Tag(标签)不是Tab按钮上的文字。 而要设置tab的label和content需要设置TabHost.TabSpec类。引用SDK里面的话——“A tab has a tab indicator, content, and a tag that is used to keep track of it.”TabHost.TabSpec就是管理这3个东西 public String getTag () public TabHost.TabSpec setContent public TabHost.TabSpec setIndicator 我理解这里的 Indicator就是Tab上的label它可以 设置label setIndicator (CharSequence label) 或者同时 设置label和icon setIndicator (CharSequence label, Drawable icon) 或者直接 指定某个view setIndicator (View view) 对于 Content就是Tab里面的内容可以 设置View的id setContent(int viewId) 或者 TabHost.TabContentFactory的createTabContent(String tag)来处理 setContent(TabHost.TabContentFactory contentFactory) 或者用 new Intent来引入其他Activity的内容 setContent(Intent intent) 现在来看官方的Views/Tabs/Content By Id例子 代码 publicclassTabs1extendsTabActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); TabHosttabHost=getTabHost(); LayoutInflater.from(this).inflate(R.layout.tabs1,tabHost.getTabContentView(),true); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("tab1") .setContent(R.id.view1)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("tab2") .setContent(R.id.view2)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("tab3") .setContent(R.id.view3)); } } 原来在获取TabHost后需要用LayoutInflater来得到LayoutLayoutInflater在后面就详细介绍。R.layout.tabs1的内容 <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextViewandroid:id="@+id/view1" android:background="@drawable/blue" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/tabs_1_tab_1"/> <TextViewandroid:id="@+id/view2" android:background="@drawable/red" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/tabs_1_tab_2"/> <TextViewandroid:id="@+id/view3" android:background="@drawable/green" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/tabs_1_tab_3"/> </FrameLayout> <!--strings.xml <stringname="tabs_1_tab_1">tab1</string> <stringname="tabs_1_tab_2">tab2</string> <stringname="tabs_1_tab_3">tab3</string> --> 原来是用FrameLayout的 而让Tab1的内容显示tab1且背景为Blue是setContent(R.id.view1)这里引用了TextView1。现在就基本明白如何添加tab以及如何设置label和content了。 接下来看看Views/Tabs/Content By Factory的例子 代码 publicclassTabs2extendsTabActivityimplementsTabHost.TabContentFactory{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); finalTabHosttabHost=getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("tab1",getResources().getDrawable(R.drawable.star_big_on)) .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("tab2") .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("tab3") .setContent(this)); } publicViewcreateTabContent(Stringtag){ finalTextViewtv=newTextView(this); tv.setText("Contentfortabwithtag"+tag); returntv; } } 可以看到通过override重写重新实现父类TabHost.TabContentFactory中的方法View createTabContent(String tag)来实现不同tab的不同content。同时在setContent的参数设置为相应的TabContentFactory。 原来createTabContent是在每个tab第一次显示时才调用的随后再次显示该tab就不会再次调用的我自己用Logcat查看到的这一点很关键就是说在createTabContent是在tab没有完全创建前调用的这意味在createTabContent里面是不能调用getCurrentTabView等之类的函数的否则就出错 至于Views/Tabs/Content By Intent例子就只是贴出代码不给截图了 publicclassTabs3extendsTabActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); finalTabHosttabHost=getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(newIntent(this,List1.class))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("photolist") .setContent(newIntent(this,List8.class))); //Thistabsetstheintentflagsothatitisrecreatedeachtime //thetabisclicked. tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("destroy") .setContent(newIntent(this,Controls2.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); } } 效果Tab1的内容是List1的ActivityTab2的是List8的ActivityTab3的是controls2.Activity。 TabHost.OnTabChangeListener TabHost.OnTabChangeListener接口只有一个抽象方法onTabChanged(String tagString)明显地在 onTabChanged(String tagString)方法里面swtich..case..来判断tagString分别处理就行了。 TabHost.setup() 在此贴出SDK doc里面的相关解释 public void setup () Since: API Level 1 Call setup() before adding tabs if loading TabHost using findViewById(). However, You do not need to call setup() after getTabHost() in TabActivity. Example: mTabHost = (TabHost)findViewById(R.id.tabhost); mTabHost.setup(); mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); //我的理解是如果要用到findViewById来获取TabHost然后add tabs的话需要在addTab前call setup(); public void setup (LocalActivityManager activityGroup) Since: API Level 1 If you are using setContent(android.content.Intent), this must be called since the activityGroup is needed to launch the local activity. This is done for you if you extend TabActivity. Parameters activityGroup Used to launch activities for tab content. 本文转自 Icansoft 51CTO博客原文链接http://blog.51cto.com/android/315208

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

Android:UI控件AutoCompleteTextView、MultiAutoCompleteTextView、include、mer...

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 public class MainActivity extends Activity { /* * 1.ems 输入长度 * 2.inputType 输入类型 * * 3.completeTextView设置: * android:completionThreshold="1" 设置从第几个字母开始查询记录 * * 4.<requestFocus />默认获得焦点 * * 5.复用控件的方法:可再设置属性 * <include layout="@layout/relayout" * android:layout_width="match_parent" * android:layout_height="match_parent" * android:layout_below="@+id/autoCompleteTextView1" /> * * 6.当根布局是framelayout时,可以使用merge复用系统的布局,合并重复的layout * <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> * </merge> */ @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter<String> adapter = new ArrayAdapter<String>( this , android.R.layout.simple_dropdown_item_1line, COUNTRIES); AutoCompleteTextView cTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); cTextView.setAdapter(adapter); MultiAutoCompleteTextView mulcTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1); mulcTextView.setAdapter(adapter); mulcTextView.setTokenizer( new MultiAutoCompleteTextView.CommaTokenizer()); //tokenizer关键分隔符 String str = "dafs,asdfa,dafdaf,dasfdsaff,trhfd,gfdhyj,hgjff" ; StringTokenizer tokenizer = new StringTokenizer(str, "," ); while (tokenizer.hasMoreElements()) { Object nextments = tokenizer.nextElement(); System.out.println(nextments); } } static final String[] COUNTRIES = new String[] { "Afghanistan" , "Albania" , "Algeria" , "American Samoa" , "Andorra" , "Angola" , "Anguilla" , "Antarctica" , "Antigua and Barbuda" , "Argentina" , "Armenia" , "Aruba" , "Australia" , "Austria" , "Azerbaijan" , "Bahrain" , "Bangladesh" , "Barbados" , "Belarus" , "Belgium" , "Belize" , "Benin" , "Bermuda" , "Bhutan" , "Bolivia" }; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true ; } } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1203963,如需转载请自行联系原作者

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

IOS UI 2013-8-9学习笔录

1.设置控件属性: 按住鼠标右键,然后拖放到controller.h,如果设置成 @property(retain,nonatomic)IBOutletUILabel*label; @property(retain,nonatomic)IBOutletUIButton*leftButton; 就是该ViewController的属性,可以在.m文件中使用self.label获取到该控件; 例如: [self.leftButtonsetTitle:@"LOVE"forState:UIControlStateHighlighted]; 就是点击按住按钮不放,然后按钮中文本会编程LOVE,但松手之后还会复原。 2.设置控件方法 按住鼠标右键,然后拖放到controller.h,如果选择IBAction的话就设置的是方法属性 - (IBAction)leftClick:(id)sender; - (IBAction)rightClick:(id)sender; 可以在.m文件中在自动生成的点击方法里面添加逻辑代码: 例如: - (IBAction)rightClick:(id)sender { self.label.text=@"right"; } 3.处理两个按钮同时拥有同一个事件,怎么区分? 如果两个按钮同时指向拥有一个同一个click方法,但我们要知道是哪个按钮点击了该方法,那我们就要通过方法的click:(id)sender这个参数来识别是哪个按钮触发了该事件,最好是给每一个按钮设置一个tag来唯一标识每个按钮,然后在.m文件中通过宏定义来设置这些tag 例如: #define LEFT_BUTTON_Tag 1 #define RIGHT_BUTTON_Tag 2 -(IBAction)click:(id)sender { UIButton *button = (UIButton *)sender; if(button.tag == LEFT_Button_Tag) { self.Label.text = @"Left click"; } } 常用函数: -(void)removeFromSuperview; -(void)insertSubview:(UIView *)view atIndex:(NSInteger)index; -(void)exchangeSubviewAtIndex:(NSInterger)index1 withSubviewAtIndex:(NSInteger)index2; -(void)addSubview:(UIView *)view; -(UIView *)viewWithTag:(NSInteger)tag; 4.通过代码重新设置Lable大小: CGRect frame = CGRectMake(100,100,200,100); //测试之前先将Use Autolayout的功能不选,让我们自己来对label大小适合文字布局 //求字体大小 //在原来的基础上添加 self.label.text = str; //求字体的长度大小,隐藏在CGSize的分类方法中 CGSize size = [str sizeWithFont:self.label.font]; //自定义长方形大小 CGRect frame = CGRectMake(self.label.frame.origin.x,self.label.frame.origin.y,size.width,self.label.frame.size.height); //通过自己设置的frame大小来改变当前label长度的大小 self.lable.frame = frame; 额外方法: CGSize labelSize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; 意思就是:把字符串s当成font字体时候,在区间size内使用这行的情况下那么s应该有的大小,也就是s在最大size范围内的宽和高 将一个view添加到另外一个view中 [self.view addSubview:label2];//添加了之后计数器加1,要释放 [label2 release]; 本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366441,如需转载请自行联系原作者

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

Android优化——UI优化(一)优化布局层次

优化布局层次 1.避免布局镶嵌过深(如下) <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:id="@+id/main_ll_duoyu" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:layout_gravity="center_vertical" > <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout> </LinearLayout> 我们完全可以去掉id为:main_ll_duoyu的这个LinearLayout,也可以实现我们想要的效果(效果如下) 2.使用工具查看布局 工具路径 sdk\tools\hierarchyviewer.bat | 双击打开 查看布局对比 我们现在去掉了main_ll_duoyu的这个LinearLayout,我们比一下前两张图和最有一张图,中间少了一层,这里只是给举个例子,可以使用google提供的这些工具帮助我们优化app,增加用户体验的流畅性 3.默认最大布局深度 android 默认的对打布局深度为10 本文转自 一点点征服 博客园博客,原文链接: http://www.cnblogs.com/ldq2016/p/5226571.html ,如需转载请自行联系原作者

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

Android UI开发第三篇——popupwindow

PopupWindow在android.widget包下,弹出窗口的形式展示。官方文档对该控件的描述是:“一个弹出窗口控件,可以用来显示任意视图(View),而且会浮动在当前 活动(activity)的顶部”。PopupWindow可以让我们实现多种自定义控件,例如:menu、alertdialog等弹窗似的View。 popupwindow需要在onCreate时初始化、通过触发事件展示出来。 public class ShowPopupWindow extends Activity implements View.OnClickListener{ View view; PopupWindow pop; Button btnShowAsDrawDown; Button btnShowAsDrawDown1; Button btnShowAtLocation; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.popup_activity); btnShowAsDrawDown = (Button)findViewById(R.id.btnShowAsDrawDown); btnShowAsDrawDown.setOnClickListener(this); btnShowAsDrawDown = (Button)findViewById(R.id.btnShowAsDrawDown1); btnShowAsDrawDown.setOnClickListener(this); btnShowAtLocation = (Button)findViewById(R.id.btnShowAt); btnShowAtLocation.setOnClickListener(this); initPopupWindow(); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btnShowAsDrawDown: if(pop.isShowing()) { pop.dismiss(); } else { pop.showAsDropDown(v); } break; case R.id.btnShowAsDrawDown1: if(pop.isShowing()) { pop.dismiss(); } else { pop.showAsDropDown(v, 0, -160); } break; default: if(pop.isShowing()) { pop.dismiss(); } else { pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER_HORIZONTAL, 0, 0); } break; } } private void initPopupWindow() { view = this.getLayoutInflater().inflate(R.layout.popup_window, null); pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); pop.setOutsideTouchable(true); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub pop.dismiss(); } }); } } popup_activity.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/main" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="pop demo!" /> <Button android:id="@+id/btnShowAsDrawDown" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Show as drawndown(one parameter)" /> <Button android:id="@+id/btnShowAsDrawDown1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Show as drawndown(three parameters)" /> <Button android:id="@+id/btnShowAt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Show At Location" /> </LinearLayout> popup_window.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center_horizontal" android:background="#d3d3d3"> <Button android:id="@+id/btn_pop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Close" android:layout_margin="10dip" /> </LinearLayout> 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817389 ,如需转载请自行联系原作者

资源下载

更多资源
Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

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

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册