首页 文章 精选 留言 我的

精选列表

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

Android:UI控件风格与主题、selector、Theme

注:默认设置放在最后。 1.颜色xml:values-->resources-->color.xml 1 2 3 4 5 6 <?xmlversion= "1.0" encoding= "utf-8" ?> <resources> <colorname= "yellow" >#FFFF00</color> <colorname= "zise" >#D15FEE</color> <colorname= "lightblue" >#8DB6CD</color> </resources> 2.颜色selector:Color List-->selector-->/color/xxx.xml 1 2 3 4 5 6 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:color= "@color/yellow" /> <itemandroid:color= "@color/zise" /> </selector> 3.尺寸(文件大小、控件大小等)dimens:values-->dimens.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <resources> <!--Defaultscreenmargins,pertheAndroidDesignguidelines.--> <dimenname= "activity_horizontal_margin" >16dp</dimen> <dimenname= "activity_vertical_margin" >16dp</dimen> <dimenname= "btn_head_width" >100dp</dimen> <dimenname= "btn_head_high" >100dp</dimen> <dimenname= "edit_width" >200dp</dimen> <dimenname= "edit_high" >60dp</dimen> <dimenname= "edit_width_xhdpi" >60dp</dimen> <dimenname= "edit_high_xhdpi" >160dp</dimen> <dimenname= "textsize" >20dp</dimen> <dimenname= "EditText_layout_marginTop" >80dp</dimen> <dimenname= "textView_layout_marginTop" >26dp</dimen> </resources> 4.背景图片:Drawable-->selector-->/drawable/xxx.xml 1 2 3 4 5 6 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:drawable= "@drawable/ic_pressed" ></item> <itemandroid:drawable= "@drawable/ic_default" ></item> </selector> 5.主题相关 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 常用的系统主题: 1 .没有标题: @android :style/Theme.Black.NoTitleBar 2 .全屏幕 @android :style/Theme.Black.NoTitleBar.Fullscreen 3 .透明 @android :style/Theme.Translucent 4 .桌面壁纸作为背景 @android :style/Theme.Wallpaper 5 .对话框 @android :style/Theme.Dialog 对Activity的生命周期是否有影响? 练习:第一个Activity中有两个按钮, 一个弹出对话框主题的Activity, 另一个弹出对话框,测试二者对 第一个Activity生命周期是否有影响。 弹出对话框主题的Activity: 暂停状态,onPause() 弹出对话框 生命周期没有影响 使用场景: 1 .对话框主题的Activity 例如:在桌面弹出短信内容对话框 对话框后面的Activity是其他App的,这时必须使用对话框主题的 Activity 2 .对话框 需要使用Activity中的成员变量时 6.设置一按钮点击时图片和文字颜色都有高亮效果 1 2 3 4 5 6 7 8 9 10 11 12 13 <TextView android:id= "@+id/home_tv_city" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentLeft= "true" android:layout_centerVertical= "true" android:drawableLeft= "@drawable/selector_home_citymore" android:drawablePadding= "4dp" android:gravity= "center" android:paddingRight= "12dp" android:text= "厦门" android:textColor= "@color/selector_home_city" android:textSize= "20sp" /> res/drawable/selector_home_citymore.xml代码: 1 2 3 4 5 6 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:drawable= "@drawable/home_morecity_pre" ></item> <itemandroid:drawable= "@drawable/home_morecity_nor" ></item> </selector> res/color/selector_home_city.xml代码: 1 2 3 4 5 6 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:color= "@color/cyan" /> <itemandroid:color= "@color/white" /> </selector> 7.创建一个shape的selector 1 2 3 4 5 6 7 8 9 10 11 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" ><shape> <solidandroid:color= "@color/gray_text" /> </shape></item> <item><shape> <solidandroid:color= "@color/touming" /> </shape></item> </selector> 8.代码编写selector 范例: 布局xml代码: 1 2 3 4 5 6 7 8 <TextView android:id= "@+id/TextView_title" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:focusable= "true" android:drawableTop= "@drawable/selector_tabwidget_icon" android:textAlignment= "center" /> selector的xml代码: 1 2 3 4 5 6 7 8 9 10 11 12 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <!--Nonfocusedstates--> <itemandroid:state_focused= "false" android:state_selected= "false" android:state_pressed= "false" android:drawable= "@drawable/contact" /> <itemandroid:state_focused= "false" android:state_selected= "true" android:state_pressed= "false" android:drawable= "@drawable/contact_sel" /> <!--Focusedstates--> <itemandroid:state_focused= "true" android:state_selected= "false" android:state_pressed= "false" android:drawable= "@drawable/contact_sel" /> <itemandroid:state_focused= "true" android:state_selected= "true" android:state_pressed= "false" android:drawable= "@drawable/contact_sel" /> <!--Pressed--> <itemandroid:state_selected= "true" android:state_pressed= "true" android:drawable= "@drawable/contact_sel" /> <itemandroid:state_pressed= "true" android:drawable= "@drawable/contact_sel" /> </selector> selector的java代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 StateListDrawabledrawable= new StateListDrawable(); //Nonfocusedstates drawable.addState( new int []{-android.R.attr.state_focused,-android.R.attr.state_selected,-android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact)); drawable.addState( new int []{-android.R.attr.state_focused,android.R.attr.state_selected,-android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact_sel)); //Focusedstates drawable.addState( new int []{android.R.attr.state_focused,-android.R.attr.state_selected,-android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact_sel)); drawable.addState( new int []{android.R.attr.state_focused,android.R.attr.state_selected,-android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact_sel)); //Pressed drawable.addState( new int []{android.R.attr.state_selected,android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact_sel)); drawable.addState( new int []{android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.contact_sel)); TextViewtextView=(TextView)findViewById(R.id.TextView_title); textView.setCompoundDrawablesWithIntrinsicBounds( null ,drawable, null , null ); 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1208480,如需转载请自行联系原作者

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

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 ,如需转载请自行联系原作者

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

Appium Android UI自动化简介 + 实战

一、自动化比较适合的场景 1、稳定迭代; 2、回归阶段;回归上一版功能,对新功能不适用。 3、研发驱动的底层代码重构; 不适合case:无网、支付、需要数据准备的case 二、Appium简介 Appium是目前最为强大的自动化测试框架,支持IOS 与Android。 IOS: 苹果公司的 UIAutomation。 Android 4.2+: Google公司的 UiAutomator。 Android 2.3+: Google公司的 Instrumentation. (Instrumentation 的支持是通过绑定另外一个独立的Selendroid项目来实现的)。 C/S 架构 Appium的核心是一个遵守REST设计风格的web 服务器,它接受客户端的连接,接收客户端的命令,在手机设备上执行命令,然后通过HTTP的响应收集命令执行的结果。 支持多语言 三、case编写思路 过程抽象: 定位-------操作-------等待---------校验---------定位 定位方式 1、文案 2、id 3、xpath 4、类名 5、属性 6、组合 PS:元素信息通过UIAutomator Viewer工具查看: 操作 1、点击;2、输入;3、滑动; 等待、判断页面元素出现或者消失: 1、 sleep 2、 View或文案显示 3、 View或文案消失 校验 按需求~文案显示或消失,View显示或消失,Dialog消失或消失,Toast等等 四、操作步骤 1、JDK、Android、eclipse、appium 等环境安装 2、启动appium server端 3、run,举例说明~~ /** * example用例 */ @Test public void test_000_example() { Gotocate(1); Sleep(2000); //文案 driver.findElementByAndroidUIAutomator("new UiSelector().text(\"餐饮\")").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/back").click(); Sleep(2000); //id driver.findElementById("com.baidu.lbs.waimai:id/left_container").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/actionbar_left").click(); Sleep(1000); //xpath driver.findElementByXPath("//android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/back").click(); Sleep(2000); //类名--推荐在View数量小的页面使用 //滑动--下拉 int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; for(int i = 0; i < 10; i++) { driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, 1000); } // WaitForStringShow("餐饮"); // WaitForViewShow("com.baidu.lbs.waimai:id/left_container"); // WaitForViewHide("com.baidu.lbs.waimai:id/left_container"); } 五、失败case问题定位 三种可能:1、bug—>提icafe;2、脚本问题->Fix;3、工具问题->寻求其他方式解决;4、环境准备问题(无网、手机无电、有弹窗、目标app后台未杀死等等) 定位问题方式: 1、查看失败case截图 2、定位代码行,查看出错原因(函数级) 3、结合功能,确定出错点 特例:crash,无结果收集,需手工复现

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

iOS_UI进阶【拖拽排序】的实现

导读 拖拽排序是新闻类的App可以说是必有的交互设计,如今日头条,网易新闻等。拖拽排序是一个交互体验非常好的设计,简单,方便。 github地址:https://github.com/HelloYeah/DraggingSort 欢迎Star,予人玫瑰,手有余香。 今日头条的拖拽排序界面 我实现的长按拖拽排序效果 实现方案 1.给CollectionViewCell添加一个长按手势,通过协议把手势传递到collectionView所在的控制器中。 - (void)awakeFromNib{ self.layer.cornerRadius = 3; self.layer.masksToBounds = YES; //给每个cell添加一个长按手势 UILongPressGestureRecognizer * longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; longPress.delegate = self; [self addGestureRecognizer:longPress]; } - (void)longPress:(UILongPressGestureRecognizer *)longPress{ if (self.delegate && [self.delegate respondsToSelector:@selector(longPress:)]) { [self.delegate longPress:longPress]; } } 2.开始长按时对cell进行截图,并隐藏cell。 - (void)longPress:(UILongPressGestureRecognizer *)longPress{ //记录上一次手势的位置 static CGPoint startPoint; //触发长按手势的cell MovingCell * cell = (MovingCell *)longPress.view; //开始长按 if (longPress.state == UIGestureRecognizerStateBegan) { [self shakeAllCell]; //获取cell的截图 _snapshotView = [cell snapshotViewAfterScreenUpdates:YES]; _snapshotView.center = cell.center; [_collectionView addSubview:_snapshotView]; _indexPath= [_collectionView indexPathForCell:cell]; _originalCell = cell; _originalCell.hidden = YES; startPoint = [longPress locationInView:_collectionView]; } 3、在手势移动的时候,移动截图视图,用遍历的方法求出截图移动到哪个cell的位置,再调用系统的api交换这个cell和隐藏cell的位置,并且数据源中的数据也需要调整顺序 //手势移动的时候 else if (longPress.state == UIGestureRecognizerStateChanged){ CGFloat tranX = [longPress locationOfTouch:0 inView:_collectionView].x - startPoint.x; CGFloat tranY = [longPress locationOfTouch:0 inView:_collectionView].y - startPoint.y; //设置截图视图位置 _snapshotView.center = CGPointApplyAffineTransform(_snapshotView.center, CGAffineTransformMakeTranslation(tranX, tranY)); startPoint = [longPress locationOfTouch:0 inView:_collectionView]; //计算截图视图和哪个cell相交 for (UICollectionViewCell *cell in [_collectionView visibleCells]) { //跳过隐藏的cell if ([_collectionView indexPathForCell:cell] == _indexPath) { continue; } //计算中心距 CGFloat space = sqrtf(pow(_snapshotView.center.x - cell.center.x, 2) + powf(_snapshotView.center.y - cell.center.y, 2)); //如果相交一半且两个视图Y的绝对值小于高度的一半就移动 if (space <= _snapshotView.bounds.size.width * 0.5 && (fabs(_snapshotView.center.y - cell.center.y) <= _snapshotView.bounds.size.height * 0.5)) { _nextIndexPath = [_collectionView indexPathForCell:cell]; if (_nextIndexPath.item > _indexPath.item) { for (NSUInteger i = _indexPath.item; i < _nextIndexPath.item ; i ++) { [self.array exchangeObjectAtIndex:i withObjectAtIndex:i + 1]; } }else{ for (NSUInteger i = _indexPath.item; i > _nextIndexPath.item ; i --) { [self.array exchangeObjectAtIndex:i withObjectAtIndex:i - 1]; } } //移动 [_collectionView moveItemAtIndexPath:_indexPath toIndexPath:_nextIndexPath]; //设置移动后的起始indexPath _indexPath = _nextIndexPath; break; } } 4.手势停止时,移除截图的view,显示隐藏cell //手势停止时 }else if(longPress.state == UIGestureRecognizerStateEnded){ [self stopShake]; [_snapshotView removeFromSuperview]; _originalCell.hidden = NO; } 其他 代码还可以进一步封装,写一个数据管理类dataTool,dataTool作为collectionView的数据源,所有的数据源方法都写到dataTool类中。手势的代理方法也在里面实现,这样控制器会简洁很多,控制器就不需要关注拖拽排序的具体逻辑了。大家有空可以自己写写看,也许你们有更好的处理方案,可以评论交流一下。 github地址:https://github.com/HelloYeah/DraggingSort 提示 如果你们是从iOS9开始适配的话,那么可以用系统的Api,非常简单好用 //是否允许拖拽 - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(9_0); /** * 从sourceIndexPath 拖拽至destinationIndexPath,在这个代理方法里修改数据源即可。 * exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex: destinationIndexPath.item */ - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath NS_AVAILABLE_IOS(9_0);

资源下载

更多资源
Mario

Mario

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

腾讯云软件源

腾讯云软件源

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

Nacos

Nacos

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

WebStorm

WebStorm

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

用户登录
用户注册