何谓标签 印象最深刻的应该是这个
现在 我们将通过一系列的扩展来研究之
写道
1. 自定义TabActivity 使得标签处于屏幕下方
2. 各个标签所用布局 既可在 *.xml 中定义 也可在 *.java 中定义
3. 更改标签布局
1. 标签页 在 屏幕下方
写道
一个典型的标签Activity 是由2 部分构成的 且其id都有规定 即:
* TabWidget 用于展示标签页 id=tabs
* FrameLayout 用于展示隶属于各个标签的具体布局 id=tabcontent
* 基本布局如下:
- <?xmlversion="1.0"encoding="utf-8"?>
-
<TabHostxmlns:android="http://schemas.android.com/apk/res/android"
-
android:id="@android:id/tabhost"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent">
-
<LinearLayout
-
android:orientation="vertical"
-
android:gravity="bottom"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent">
-
<FrameLayout
-
android:id="@android:id/tabcontent"
-
android:layout_width="fill_parent"
-
android:layout_height="200dip">
-
-
<RelativeLayout
-
android:id="@+id/view1"
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
>
-
<TextView
-
android:id="@+id/text"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="HellotoJohnny.Griffin!"
-
android:layout_centerInParent="true"
-
android:textStyle="bold|italic"/>
-
<ImageView
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:src="@drawable/robot"
-
android:layout_toLeftOf="@id/text"/>
-
</RelativeLayout>
-
-
<TextView
-
android:id="@+id/view2"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="创新源于模仿!"/>
-
-
<TextView
-
android:id="@+id/view3"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="欢迎进入droid世界!"/>
-
-
<ImageView
-
android:id="@+id/view4"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:src="@drawable/robot"/>
-
</FrameLayout>
-
<TabWidget
-
android:id="@android:id/tabs"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"/>
-
</LinearLayout>
-
</TabHost>
* 得到TabHost tHost 仅在TabActivity中有效
* 创建4个标签 并指定所使用的布局
- publicstaticfinalStringTab1="Tab1";
-
publicstaticfinalStringTab2="Tab2";
-
publicstaticfinalStringTab3="Tab3";
-
publicstaticfinalStringTab4="Tab4";
-
publicstaticfinalStringTab5="Tab5";
-
tHost.addTab(tHost.newTabSpec(Tab1).setIndicator("Tab1",getResources().getDrawable(R.drawable.icon)).setContent(R.id.view1));
-
tHost.addTab(tHost.newTabSpec(Tab2).setIndicator("Tab2",getResources().getDrawable(R.drawable.beijing_small)).setContent(R.id.view2));
-
tHost.addTab(tHost.newTabSpec(Tab3).setIndicator("Tab3").setContent(R.id.view3));
-
tHost.addTab(tHost.newTabSpec(Tab4).setIndicator("Tab4").setContent(R.id.view4));
* 设定监听器 用于监听 标签间切换事件
- tHost.setOnTabChangedListener(newOnTabChangeListener(){
-
@Override
-
publicvoidonTabChanged(StringtabId){
-
- }
-
- });
* emulator 运行情况:
2. 在 *.java 中定义标签所需布局
- publicclassCustomLayoutimplementsTabHost.TabContentFactory{
- Activityactivity;
- LayoutInflaterinflaterHelper;
-
- LinearLayoutlayout;
-
-
publicCustomLayout(Activitya){
- activity=a;
-
- inflaterHelper=a.getLayoutInflater();
- }
-
-
//tag标记各个标签
-
publicViewcreateTabContent(Stringtag){
-
returnaddCustomView(tag);
- }
-
-
publicViewaddCustomView(Stringid){
-
-
layout=newLinearLayout(activity);
- layout.setOrientation(LinearLayout.VERTICAL);
-
-
-
if(id.equals(Tab1)){
-
ImageViewiv=newImageView(activity);
- iv.setImageResource(R.drawable.beijing_big);
- layout.addView(iv,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
- }
-
elseif(id.equals(Tab2)){
-
EditTextedit=newEditText(activity);
- layout.addView(edit,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
-
-
Buttonbtn=newButton(activity);
-
btn.setText("OK");
-
btn.setWidth(100);
- layout.addView(btn,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
-
-
RadioGrouprGroup=newRadioGroup(activity);
- rGroup.setOrientation(LinearLayout.HORIZONTAL);
-
RadioButtonradio1=newRadioButton(activity);
-
radio1.setText("RadioA");
- rGroup.addView(radio1);
-
RadioButtonradio2=newRadioButton(activity);
-
radio2.setText("RadioB");
- rGroup.addView(radio2);
-
- layout.addView(rGroup,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
- }
-
elseif(id.equals(Tab3)){
-
- LinearLayout.LayoutParamsparam3=
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
-
-
layout.addView(inflaterHelper.inflate(R.layout.hello,null),param3);
- }
-
elseif(id.equals(Tab4)){
-
TextViewtv=newTextView(activity);
-
tv.setText("HelloTags!");
- tv.setGravity(Gravity.CENTER);
- layout.addView(tv);
- }
-
returnlayout;
- }
-
- }
* 如何使用:
- CustomLayoutct=newCustomLayout(this);
-
tHost.addTab(tHost.newTabSpec(Tab4).setIndicator("Tab4").setContent(ct));
* emulator 运行结果:
3. 改变标签布局
写道
可能很多人对TabActivity 不满意 原因之一:其很不美观 而不美观的根源就是:标签的问题 其图像和文字相互覆盖 导致的
那么 我们可以自己扩展么? 当然
写道
TabWidget 理解:
1. TabWidget 为 horizontal 的 LinearLayout
2. 且 其包含的标签又是一个RelativeLayout
3. 每个标签RelativeLayout 里面包含2个View: TextView ImageView
因此 我们甚至可以推算出其布局为:
- <?xmlversion="1.0"encoding="utf-8"?>
-
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="horizontal"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
- >
- <RelativeLayout
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content">
- <ImageView/>
- <TextView/>
- </RelativeLayout>
- <RelativeLayout
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content">
- <ImageView/>
- <TextView/>
- </RelativeLayout>
- <RelativeLayout
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content">
- <ImageView/>
- <TextView/>
- </RelativeLayout>
- <RelativeLayout
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content">
- <ImageView/>
- <TextView/>
- </RelativeLayout>
- </LinearLayout>
* 去掉系统默认的布局 即 在 setIndicator() 中置空 修改如下:
- tHost.addTab(tHost.newTabSpec(Tab1).setIndicator("").setContent(ct));
写道
可能有人会说:那我不调用setIndicator() 不久可以了么 不行 否则 会报错
* 自己定义布局 并 指定显示的内容
- publicViewcomposeLayout(Strings,inti){
-
LinearLayoutlayout=newLinearLayout(this);
- layout.setOrientation(LinearLayout.VERTICAL);
-
-
TextViewtv=newTextView(this);
- tv.setGravity(Gravity.CENTER);
-
tv.setSingleLine(true);
- tv.setText(s);
- layout.addView(tv,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
-
-
ImageViewiv=newImageView(this);
- iv.setImageResource(i);
- layout.addView(iv,
-
newLinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
-
returnlayout;
- }
* 得到 TabWidget 实例 tw
- LinearLayoutll=(LinearLayout)tHost.getChildAt(0);
-
tw=(TabWidget)ll.getChildAt(1);
* 得到 TabWidget 内的具体某个Layout 并使用上面的布局 composeLayout()
- publicvoidupdateWidgetView(inti,Stringtext,intimage){
- RelativeLayoutrl=(RelativeLayout)tw.getChildAt(i);
-
- rl.addView(composeLayout(text,image));
- }
* emulator 运行截图 // 前面 3个是使用新布局 最后一个是使用TabActivity 默认的布局 哪个好看 大家自己选择之
that's all!
分享到:
相关推荐
一个简单的Fragment + TabActivity实现标签内跳转demo, 本来要用ViewPager的,但是发现有些东西和自己原来想的不一样, 下个版本再实现吧。
使用说明,请参考网页:http://blog.csdn.net/tabactivity/article/details/10721521
一个简单的TabActivity自定义实现标签换页例子
make_ext4fs,linux下system.img打包工具 使用教程参见: https://blog.csdn.net/tabactivity/article/details/125993855
使用 TabActivity 实现滑动翻页(带动画)和标签置底
NULL 博文链接:https://hao3100590.iteye.com/blog/974343
Obfuscation.sh,Obfuscation移植到LLVM10.0.1以及更高版本的脚本,使用方法:https://blog.csdn.net/tabactivity/article/details/108995746
实现了Tab控件,每个TabActivity用ListView实现
利用Fragment模拟Tabactivity功能。同时也实现了ELong主界面的底部栏的动画切换功能。
需要配合 TWRP 使用。参见:https://blog.csdn.net/tabactivity/article/details/88355317 下载后push到手机,进入TWRP,选择 install 安装该文件,重启手机即可获得root权限
super.img解包打包工具--lpunpack、lpmake、lpdump linux 下可用。 解压密码:https://modun.blog.csdn.net/ 使用说明:参见我的文章 https://blog.csdn.net/tabactivity/article/details/135969964?
TabActivity 之间跳转 传值
卓岚TCP UDP调试助手+TCP-UDP服务管理V1.03+网络调试助手3.7 三个工具都在这里。 截图和说明参见我博客:https://blog.csdn.net/tabactivity/article/details/120081594 已确认正常使用。
arm32 android版pwn-level6二进制文件+gdbserver+lldb+socat,文章pwn - 零基础ROP之Android ARM 32位篇(新修订)https://blog.csdn.net/tabactivity/article/details/137780714 全部资料文件。 0基础pwn
TabActivity 实现滑动翻页(动画)
boot.img解包打包工具。这3个文件是linux程序。 需要放到linux下才能执行,记得chmod 755 这些文件权限 mkboot 就是 split_...使用方法参见我的博客https://blog.csdn.net/tabactivity/article/details/88355317
TabActivity使用实例
看到还有些人在使用TabActvity,这个已经被Google废弃了的类,为了大家方便,写了一个能代替TabActivity的东西。说白了也就是对viewpager跟底部菜单进行了一个封装,标准的底部菜单自定义控件已经写好,如果有另外的...
NULL 博文链接:https://l-x.iteye.com/blog/1408157
TabActivity探索 TabActivity探索 TabActivity探索 TabActivity探索 TabActivity探索