Android TabHost控件 右侧留空并增加按钮

涉及公司内部程序,部分地方进行模糊处理。



公司Android程序的一个子程序UI要进行改版,最初的UI添加按钮是在内容区,而且TabHost空间是正常的标题平均分布。如下图(其实这是改版的第一版,没有了添加按钮,但是还是标题还是平均分布。)




但是,后来改版后,“添加”按钮变成了这样:



这个界面上,首先,TabHost集中在左侧,然后“加号”按钮变到了右侧,而且第一和第二个Tab有按钮,第三个“设置”Tab没有加号。


由于是在原基础上改版,源程序也是原来的同事写的,所以就尽量小的改动源程序。所以在原来的自定义TabHost的基础上进行更改,如下:

[code lang="xml"] <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" android:background="@drawable/main_background" android:orientation="horizontal" > <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:layout_marginTop="0dp" android:layout_marginLeft="0dp" android:id="@android:id/tabs" android:layout_width="wrap_content" android:layout_height="68dip" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="7"> </FrameLayout> </LinearLayout> <!--在这里加一个Button --> <Button android:id="@+id/btn_add" android:layout_width="40dip" android:layout_height="40dip" android:background="@drawable/jiahao" android:layout_marginLeft="700dip" android:layout_marginTop="15dip"/> </TabHost> </LinearLayout> [/code]


在主Activity中更改onCtreate:

[java] @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); mTabHost = getTabHost(); initbacklist(); //加载黑名单; initwhitelist(); //加载白名单; firewallset(); //加载设置界面 //设置没个标题的宽度,这样Tab标题就集中在了左侧 TabWidget tabget0 = mTabHost.getTabWidget(); tabget0.getChildAt(0).getLayoutParams().width = 178; tabget0.getChildAt(1).getLayoutParams().width = 178; tabget0.getChildAt(2).getLayoutParams().width = 178; } [/java]


这样就让Tab的标题集中在左边,右侧添加了一个公共的按钮。下一次介绍如何使用公共的按钮。


转载于:https://www.cnblogs.com/mnight/p/3677659.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值