首页 文章 精选 留言 我的

精选列表

搜索[微服务脚手架],共10000篇文章
优秀的个人博客,低调大师

新浪微博布局学习——妙用TabHost

正文 一、效果图 红色部分是本文要实现的目标。 二、实现 maintabs.xml <? xmlversion="1.0"encoding="UTF-8" ?> < TabHost android:id ="@android:id/tabhost" android:layout_width ="fill_parent" android:layout_height ="fill_parent" xmlns:android ="http://schemas.android.com/apk/res/android" > < LinearLayout android:orientation ="vertical" android:layout_width ="fill_parent" android:layout_height ="fill_parent" > < FrameLayout android:id ="@android:id/tabcontent" android:layout_width ="fill_parent" android:layout_height ="0.0dip" android:layout_weight ="1.0" /> < TabWidget android:id ="@android:id/tabs" android:visibility ="gone" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_weight ="0.0" /> < RadioGroup android:gravity ="center_vertical" android:layout_gravity ="bottom" android:orientation ="horizontal" android:id ="@id/main_radio" android:background ="@drawable/maintab_toolbar_bg" android:layout_width ="fill_parent" android:layout_height ="wrap_content" > < RadioButton android:text ="@string/main_home" android:checked ="true" android:id ="@+id/radio_button0" android:layout_marginTop ="2.0dip" android:drawableTop ="@drawable/icon_1_n" style ="@style/main_tab_bottom" /> < RadioButton android:id ="@+id/radio_button1" android:layout_marginTop ="2.0dip" android:text ="@string/main_news" android:drawableTop ="@drawable/icon_2_n" style ="@style/main_tab_bottom" /> < RadioButton android:id ="@+id/radio_button2" android:layout_marginTop ="2.0dip" android:text ="@string/main_my_info" android:drawableTop ="@drawable/icon_3_n" style ="@style/main_tab_bottom" /> < RadioButton android:id ="@+id/radio_button3" android:layout_marginTop ="2.0dip" android:text ="@string/menu_search" android:drawableTop ="@drawable/icon_4_n" style ="@style/main_tab_bottom" /> < RadioButton android:id ="@+id/radio_button4" android:layout_marginTop ="2.0dip" android:text ="@string/more" android:drawableTop ="@drawable/icon_5_n" style ="@style/main_tab_bottom" /> </ RadioGroup > </ LinearLayout > </ TabHost > styles.xml < style name ="main_tab_bottom" > < item name ="android:textSize" > @dimen/bottom_tab_font_size </ item > < item name ="android:textColor" > #ffffffff </ item > < item name ="android:ellipsize" > marquee </ item > < item name ="android:gravity" > center_horizontal </ item > < item name ="android:background" > @drawable/home_btn_bg </ item > < item name ="android:paddingTop" > @dimen/bottom_tab_padding_up </ item > < item name ="android:layout_width" > fill_parent </ item > < item name ="android:layout_height" > wrap_content </ item > < item name ="android:button" > @null </ item > < item name ="android:singleLine" > true </ item > < item name ="android:drawablePadding" > @dimen/bottom_tab_padding_drawable </ item > < item name ="android:layout_weight" > 1.0 </ item > </ style > home_btn_bg.xml < selector xmlns:android ="http://schemas.android.com/apk/res/android" > < item android:state_focused ="true" android:state_enabled ="true" android:state_pressed ="false" android:drawable ="@drawable/home_btn_bg_s" /> < item android:state_enabled ="true" android:state_pressed ="true" android:drawable ="@drawable/home_btn_bg_s" /> < item android:state_enabled ="true" android:state_checked ="true" android:drawable ="@drawable/home_btn_bg_d" /> < item android:drawable ="@drawable/transparent" /> </ selector > 代码说明: 1. 需要注意的是他这里把TabWidget的Visibility设置成了gone!也就是默认难看的风格不见了:,取而代之的是5个带风格的单选按钮. 2. 注意为单选按钮设置的style,其中最重要的是为其background设置了home_btn_bg.xml,也就是自定义了选中效果。 Java文件 public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{ private TabHostmHost; private IntentmMBlogIntent; private IntentmMoreIntent; private IntentmInfoIntent; private IntentmSearchIntent; private IntentmUserInfoIntent; @Override protected void onCreate(BundlesavedInstanceState){ super .onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.maintabs); // ~~~~~~~~~~~~初始化 this .mMBlogIntent = new Intent( this ,HomeListActivity. class ); this .mSearchIntent = new Intent( this ,SearchSquareActivity. class ); this .mInfoIntent = new Intent( this ,MessageGroup. class ); this .mUserInfoIntent = new Intent( this ,MyInfoActivity. class ); this .mMoreIntent = new Intent( this ,MoreItemsActivity. class ); initRadios(); setupIntent(); } /** *初始化底部按钮 */ private void initRadios(){ ((RadioButton)findViewById(R.id.radio_button0)).setOnCheckedChangeListener( this ); ((RadioButton)findViewById(R.id.radio_button1)).setOnCheckedChangeListener( this ); ((RadioButton)findViewById(R.id.radio_button2)).setOnCheckedChangeListener( this ); ((RadioButton)findViewById(R.id.radio_button3)).setOnCheckedChangeListener( this ); ((RadioButton)findViewById(R.id.radio_button4)).setOnCheckedChangeListener( this ); } /** *切换模块 */ @Override public void onCheckedChanged(CompoundButtonbuttonView, boolean isChecked){ if (isChecked){ switch (buttonView.getId()){ case R.id.radio_button0: this .mHost.setCurrentTabByTag( " mblog_tab " ); break ; case R.id.radio_button1: this .mHost.setCurrentTabByTag( " message_tab " ); break ; case R.id.radio_button2: this .mHost.setCurrentTabByTag( " userinfo_tab " ); break ; case R.id.radio_button3: this .mHost.setCurrentTabByTag( " search_tab " ); break ; case R.id.radio_button4: this .mHost.setCurrentTabByTag( " more_tab " ); break ; } } } private void setupIntent(){ this .mHost = getTabHost(); TabHostlocalTabHost = this .mHost; localTabHost.addTab(buildTabSpec( " mblog_tab " ,R.string.main_home, R.drawable.icon_1_n, this .mMBlogIntent)); localTabHost.addTab(buildTabSpec( " message_tab " ,R.string.main_news, R.drawable.icon_2_n, this .mInfoIntent)); localTabHost.addTab(buildTabSpec( " userinfo_tab " ,R.string.main_my_info, R.drawable.icon_3_n, this .mUserInfoIntent)); localTabHost.addTab(buildTabSpec( " search_tab " ,R.string.menu_search, R.drawable.icon_4_n, this .mSearchIntent)); localTabHost.addTab(buildTabSpec( " more_tab " ,R.string.more, R.drawable.icon_5_n, this .mMoreIntent)); } private TabHost.TabSpecbuildTabSpec(Stringtag, int resLabel, int resIcon, final Intentcontent){ return this .mHost .newTabSpec(tag) .setIndicator(getString(resLabel), getResources().getDrawable(resIcon)) .setContent(content); } 代码说明 1. 由于TabWidget被隐藏,所以相关的事件也会无效,这里取巧用RadioGroup与RadioButton的特性来处理切换,然后监听事件调用setCurrentTabByTag来切换Activity。 2. 注意即使TabWidget被隐藏,也要为其设置indicator,否则会保持。 三、总结 在这之前如果要做这种效果我恐怕第一时间就会想到用ActivityGroup来做,主要是因为TabHost的TabWidget非常难看,用起来也不方便。其实从源码可以看出,TabActivity也是继承自ActivityGroup,这里结合了单选按钮和TabHost,各取其长,有时间可以专门写一个这样的自定义控件:) 本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/582149,如需转载请自行联系原作者

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

新浪微博布局学习——活用RelativeLayout

正文 一、效果图 格子布局效果: (图一) 居中正在加载的效果: (图二) 二、实现代码 2.1 实现 图一 效果代码 < RelativeLayout android:id ="@id/rlDigest" android:background ="@drawable/panel_bg" android:layout_width ="fill_parent" android:layout_height ="100.0dip" android:layout_margin ="10.0dip" > < TextView android:textSize ="16.0sp" android:textColor ="#ff7d899d" android:gravity ="center_vertical" android:id ="@id/tvAddress" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_marginLeft ="5.0dip" android:layout_marginTop ="10.0dip" android:text ="@string/userinfo_address" android:layout_alignParentLeft ="true" android:layout_alignParentTop ="true" /> < TextView android:textSize ="16.0sp" android:textColor ="#ff373737" android:id ="@id/tvAddress_content" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_marginLeft ="10.0dip" android:layout_toRightOf ="@id/tvAddress" android:layout_alignTop ="@id/tvAddress" /> < View android:id ="@id/vHDivider" android:background ="@drawable/horizontal_separation_line_repeat" android:layout_width ="fill_parent" android:layout_height ="1.0dip" android:layout_centerVertical ="true" /> < TextView android:textSize ="16.0sp" android:textColor ="#ff7d899d" android:gravity ="center_vertical" android:id ="@id/tvAccount_info" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:text ="@string/account_info" android:layout_below ="@id/vHDivider" android:layout_alignLeft ="@id/tvAddress" android:layout_alignParentBottom ="true" /> < TextView android:textSize ="16.0sp" android:textColor ="#ff373737" android:gravity ="center_vertical" android:id ="@id/tvAccount_info_content" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_marginLeft ="10.0dip" android:layout_marginBottom ="12.0dip" android:singleLine ="true" android:layout_toRightOf ="@id/tvAccount_info" android:layout_alignBottom ="@id/tvAccount_info" /> </ RelativeLayout > < RelativeLayout android:background ="@drawable/panel_bg" android:layout_width ="fill_parent" android:layout_height ="130.0dip" android:layout_margin ="10.0dip" > < View android:id ="@id/vVDivider1" android:background ="@drawable/vertical_separation_line_repeat" android:layout_width ="1.0dip" android:layout_height ="fill_parent" android:layout_centerHorizontal ="true" /> < View android:id ="@id/vHDivider2" android:background ="@drawable/horizontal_separation_line_repeat" android:layout_width ="fill_parent" android:layout_height ="1.0dip" android:layout_centerVertical ="true" /> < RelativeLayout android:id ="@id/llAttention" android:background ="@drawable/bg_panel_above_left" android:clickable ="true" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toLeftOf ="@id/vVDivider1" android:layout_above ="@id/vHDivider2" android:layout_alignParentLeft ="true" android:layout_alignParentTop ="true" > < TextView android:gravity ="center" android:id ="@id/tvAttention_count" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_marginTop ="10.0dip" android:text ="0" android:layout_centerHorizontal ="true" style ="@style/userinfo_panel_textview_count" /> < TextView android:gravity ="center" android:id ="@id/tvAttention" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/attention" android:layout_below ="@id/tvAttention_count" android:layout_centerHorizontal ="true" style ="@style/userinfo_panel_textview_title" /> </ RelativeLayout > < LinearLayout android:orientation ="vertical" android:id ="@id/rlWeibo" android:background ="@drawable/bg_panel_above_right" android:clickable ="true" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toRightOf ="@id/vVDivider1" android:layout_above ="@id/vHDivider2" android:layout_alignParentTop ="true" android:layout_alignParentRight ="true" > < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvWeibo_count" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_marginTop ="10.0dip" android:text ="0" style ="@style/userinfo_panel_textview_count" /> < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvTopic" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/radio_button_topic" style ="@style/userinfo_panel_textview_title" /> </ LinearLayout > < LinearLayout android:orientation ="vertical" android:id ="@id/llFans" android:background ="@drawable/bg_panel_below_left" android:clickable ="true" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toLeftOf ="@id/vVDivider1" android:layout_below ="@id/vHDivider2" android:layout_alignParentLeft ="true" android:layout_alignParentBottom ="true" > < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvFans_count" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_marginTop ="10.0dip" android:text ="0" style ="@style/userinfo_panel_textview_count" /> < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvFans" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/fans" style ="@style/userinfo_panel_textview_title" /> </ LinearLayout > < LinearLayout android:orientation ="vertical" android:id ="@id/llTopic" android:background ="@drawable/bg_panel_below_right" android:clickable ="true" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toRightOf ="@id/vVDivider1" android:layout_below ="@id/vHDivider2" android:layout_alignParentRight ="true" android:layout_alignParentBottom ="true" > < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvTopic_count" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_marginTop ="10.0dip" android:text ="0" style ="@style/userinfo_panel_textview_count" /> < TextView android:gravity ="center" android:layout_gravity ="center_horizontal" android:id ="@id/tvTopic" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/his_topics" style ="@style/userinfo_panel_textview_title" /> </ LinearLayout > </ RelativeLayout > 代码说明: 2.1.1 第一个RelativeLayout为图一上的实现代码。注意使用了一个View,也就是一条横线,令其居中布局;"地址:"的TextView通过layout_alignParentLeft和layout_alignParentTop令其在整个RelativeLayout顶左顶上;"账号信息:"的TextView通过layout_below令其位于横线下方,layout_alignLeft令其与"地址:"的TextView左边对齐,然后用layout_alignParentBottom让其居于容器底部。 2.1.2 第二个RelativeLayout为图一下的实现代码。关键是vVDivider1和vVDivider2,与3.1.1类似,画出了一个十字架的布局,然后分别用居左、居上、居下、居右等方式实现了该布局效果。 2.2 实现 图二 效果代码 < RelativeLayout android:id ="@+id/rlpb" android:layout_width ="fill_parent" android:background ="#ffeff0f4" android:visibility ="gone" android:layout_height ="fill_parent" android:layout_weight ="1.0" > < LinearLayout android:layout_centerInParent ="true" android:layout_width ="wrap_content" android:layout_height ="wrap_content" > < ProgressBar android:id ="@+id/prb" style ="?android:attr/progressBarStyleSmallTitle" android:layout_width ="wrap_content" android:layout_height ="wrap_content" /> < TextView android:text ="@string/loadinfo" android:layout_width ="wrap_content" android:layout_height ="wrap_content" /> </ LinearLayout > </ RelativeLayout > 代码说明: 主要是layout_centerInParent属性的应用,令其居于RelativeLayout的中间。使用的时候领ListView先隐藏,然后让这个布局显示并填充,用完在设置Visible为GONE即可。 三、总结 熟练掌握以下重要属性,并灵活运用: android:layout_centerInParent 居中布局 android:layout_centerVertical 水平居中布局 android:layout_centerHorizontal 垂直居中布局 android:layout_alignParentTop 居于容器内顶部 android:layout_alignParentBottom 居于容器内底部 android:layout_alignParentLeft 居于容器内左边 android:layout_alignParentRight 居于容器内右边 android:layout_above 居于指定View的上方 android:layout_below 居于指定View的下方 android:layout_toRightOf 在指定View的右边 android:layout_toLeftOf 在指定View的左边 android:layout_alignTop 与指定View的Top一致 本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/582146,如需转载请自行联系原作者

资源下载

更多资源
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文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

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

用户登录
用户注册