最全实现屏幕下方展示的TAB分页,android游戏开发入门题大学题

最后

这里我特地整理了一份《Android开发核心知识点笔记》,里面就包含了自定义View相关的内容

除了这份笔记,还给大家分享 Android学习PDF+架构视频+面试文档+源码笔记,高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料这几块的内容。非常适合近期有面试和想在技术道路上继续精进的朋友。

分享上面这些资源,希望可以帮助到大家提升进阶,如果你觉得还算有用的话,不妨把它们推荐给你的朋友~

喜欢本文的话,给我点个小赞、评论区留言或者转发支持一下呗~

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  1. @Override

  2. public void onCreate(Bundle savedInstanceState) {

  3. super.onCreate(savedInstanceState);

  4. setContentView(R.layout.main);

  5. tabHost = getTabHost();

  6. populateTab();

  7. }

  8. /**

  9. * 组装tab控件

  10. */

  11. private void populateTab() {

  12. Resources res = getResources();

  13. populateTabItem(R.drawable.tab_home_selector,

  14. res.getString(R.string.tab_home), new Intent(this,

  15. HomeActivity.class));

  16. populateTabItem(R.drawable.tab_atme_selector,

  17. res.getString(R.string.tab_refer), new Intent(this,

  18. ReferActivity.class));

  19. populateTabItem(R.drawable.tab_message_selector,

  20. res.getString(R.string.tab_secret), new Intent(this,

  21. MessageActivity.class));

  22. populateTabItem(R.drawable.tab_explore_selector,

  23. res.getString(R.string.tab_search), new Intent(this,

  24. SearchActivity.class));

  25. populateTabItem(R.drawable.tab_focus_selector,

  26. res.getString(R.string.tab_attention), new Intent(this,

  27. AttentionActivity.class));

  28. }

  29. /**

  30. * 生成tab_item

  31. *

  32. * @param imageResourceSelector

  33. *            图片选择器

  34. * @param text

  35. *            文本

  36. * @param intent

  37. *            intent

  38. */

  39. private void populateTabItem(int imageResourceSelector, String text,

  40. Intent intent) {

  41. View view = View.inflate(this, R.layout.tab_item, null);// 拼装view

  42. ((ImageView) view.findViewById(R.id.tab_item_imageview))

  43. .setImageResource(imageResourceSelector);

  44. ((TextView) view.findViewById(R.id.tab_item_textview)).setText(text);

  45. TabSpec spec = tabHost.newTabSpec(text).setIndicator(view)

  46. .setContent(intent);// 将view注入spec

  47. tabHost.addTab(spec);

  48. }

  49. }

  50. public class MainActivity extends TabActivity {

  51. private TabHost tabHost;

  52. @Override

  53. public void onCreate(Bundle savedInstanceState) {

  54. super.onCreate(savedInstanceState);

  55. setContentView(R.layout.main);

  56. tabHost = getTabHost();

  57. populateTab();

  58. }

  59. /**

  60. * 组装tab控件

  61. */

  62. private void populateTab() {

  63. Resources res = getResources();

  64. populateTabItem(R.drawable.tab_home_selector,

  65. res.getString(R.string.tab_home), new Intent(this,

  66. HomeActivity.class));

  67. populateTabItem(R.drawable.tab_atme_selector,

  68. res.getString(R.string.tab_refer), new Intent(this,

  69. ReferActivity.class));

  70. populateTabItem(R.drawable.tab_message_selector,

  71. res.getString(R.string.tab_secret), new Intent(this,

  72. MessageActivity.class));

  73. populateTabItem(R.drawable.tab_explore_selector,

  74. res.getString(R.string.tab_search), new Intent(this,

  75. SearchActivity.class));

  76. populateTabItem(R.drawable.tab_focus_selector,

  77. res.getString(R.string.tab_attention), new Intent(this,

  78. AttentionActivity.class));

  79. }

  80. /**

  81. * 生成tab_item

  82. *

  83. * @param imageResourceSelector

  84. *            图片选择器

  85. * @param text

  86. *            文本

  87. * @param intent

  88. *            intent

  89. */

  90. private void populateTabItem(int imageResourceSelector, String text,

  91. Intent intent) {

  92. View view = View.inflate(this, R.layout.tab_item, null);// 拼装view

  93. ((ImageView) view.findViewById(R.id.tab_item_imageview))

  94. .setImageResource(imageResourceSelector);

  95. ((TextView) view.findViewById(R.id.tab_item_textview)).setText(text);

  96. TabSpec spec = tabHost.newTabSpec(text).setIndicator(view)

  97. .setContent(intent);// 将view注入spec

  98. tabHost.addTab(spec);

  99. }

  100. }

Xml代码

  1. <?xml version\="1.0" encoding\="UTF-8"?>  
  2. <TabHost android:id=“@android:id/tabhost” android:layout_width=“fill_parent”

  3. android:layout_height=“fill_parent” xmlns:android=“http://schemas.android.com/apk/res/android”>

  4. <RelativeLayout android:orientation=“vertical”

  5. android:layout_width=“fill_parent” android:layout_height=“fill_parent”>

  6. <include android:id=“@+id/head_line” layout=“@layout/head_line”

  7. android:layout_width=“fill_parent” android:layout_height=“wrap_content” />

  8. <FrameLayout android:id=“@android:id/tabcontent”

  9. android:layout_below=“@id/head_line” android:layout_width=“fill_parent”

  10. android:layout_height=“fill_parent” android:layout_weight=“1.0” />

  11. <TabWidget android:id=“@android:id/tabs” android:background=“@drawable/tab_bkg”

  12. android:layout_gravity=“bottom” android:layout_height=“60.0dip”

  13. android:layout_width=“fill_parent” android:fadingEdge=“none”

  14. android:fadingEdgeLength=“0.0px” android:paddingLeft=“0.0dip”

  15. android:paddingTop=“2.0dip” android:paddingRight=“0.0dip”

  16. android:paddingBottom=“0.0dip” android:layout_alignParentBottom=“true”

  17. android:layout_alignParentTop=“false” />

  18. </RelativeLayout>

  19. </TabHost>

  20. <?xml version\="1.0" encoding\="UTF-8"?>  
  21. <TabHost android:id=“@android:id/tabhost” android:layout_width=“fill_parent”

  22. android:layout_height=“fill_parent” xmlns:android=“http://schemas.android.com/apk/res/android”>

  23. <RelativeLayout android:orientation=“vertical”

  24. android:layout_width=“fill_parent” android:layout_height=“fill_parent”>

  25. <include android:id=“@+id/head_line” layout=“@layout/head_line”

  26. android:layout_width=“fill_parent” android:layout_height=“wrap_content” />

  27. <FrameLayout android:id=“@android:id/tabcontent”

  28. android:layout_below=“@id/head_line” android:layout_width=“fill_parent”

  29. android:layout_height=“fill_parent” android:layout_weight=“1.0” />

  30. <TabWidget android:id=“@android:id/tabs” android:background=“@drawable/tab_bkg”

  31. android:layout_gravity=“bottom” android:layout_height=“60.0dip”

  32. android:layout_width=“fill_parent” android:fadingEdge=“none”

  33. android:fadingEdgeLength=“0.0px” android:paddingLeft=“0.0dip”

  34. android:paddingTop=“2.0dip” android:paddingRight=“0.0dip”

  35. android:paddingBottom=“0.0dip” android:layout_alignParentBottom=“true”

  36. android:layout_alignParentTop=“false” />

  37. </RelativeLayout>

  38. </TabHost>

可以看到,TabActivity是继承自Activity,包含了一个TabHost组件。TabHost组件则是继承自FrameLayout的ViewGroup。

TabHost组件本身的id必须是@android:id/tabhost,它必须包含一个FrameLayout,并且该FrameLayout的id必须是@android:id/tabcontent,此外还要包含一个TabWidget,id是@android:id/tabs。

FrameLayout可以放置每个单独的Activity,而TabWidget则是每个Tab页签。默认第一个页签对应的Activity,会首先显示在FrameLayout里。然后每次点击其他的Tab页签,对应的Activity就会切换显示到FrameLayout里。这个有点类似html中的frameset的概念

2、在main.xml中有一行

Xml代码

  1. <include android:id=“@+id/head_line” layout=“@layout/head_line”

  2. android:layout_width=“fill_parent” android:layout_height=“wrap_content” />

view plain copy to clipboard print ?

  1. <include android:id=“@+id/head_line” layout=“@layout/head_line”

  2. android:layout_width=“fill_parent” android:layout_height=“wrap_content” />

作用是引入另一个View文件,head_line.xml

Xml代码

  1. <RelativeLayout android:background=“@drawable/header”

  2. android:layout_width=“fill_parent” android:layout_height=“wrap_content”

  3. xmlns:android=“http://schemas.android.com/apk/res/android”>

  4. <Button android:id=“@+id/top_btn_left” android:textColor=“@color/button_text_selector”

  5. android:background=“@drawable/top_refresh_selector”

  6. android:layout_width=“wrap_content” android:layout_height=“wrap_content”

  7. android:layout_marginLeft=“12.0dip” android:layout_alignParentLeft=“true”

  8. android:layout_centerVertical=“true” />

  9. <Button android:id=“@+id/top_btn_right” android:textColor=“@color/button_text_selector”

  10. android:background=“@drawable/top_edit_selector” android:layout_width=“wrap_content”

  11. android:layout_height=“wrap_content” android:layout_marginRight=“12.0dip”

  12. android:layout_alignParentRight=“true” android:layout_centerVertical=“true” />

  13. <TextView android:id=“@+id/top_title” android:textSize=“22.0sp”

  14. android:textColor=“@color/head_line_text” android:ellipsize=“middle”

  15. android:gravity=“center_horizontal” android:layout_width=“wrap_content”

  16. android:layout_height=“wrap_content” android:text=“@string/user_name”

  17. android:singleLine=“true” android:layout_toLeftOf=“@id/top_btn_right”

  18. android:layout_toRightOf=“@id/top_btn_left”

  19. android:layout_centerInParent=“true”

  20. android:layout_alignWithParentIfMissing=“true” />

  21. </RelativeLayout>

  22. <RelativeLayout android:background=“@drawable/header”

  23. android:layout_width=“fill_parent” android:layout_height=“wrap_content”

  24. xmlns:android=“http://schemas.android.com/apk/res/android”>

  25. <Button android:id=“@+id/top_btn_left” android:textColor=“@color/button_text_selector”

  26. android:background=“@drawable/top_refresh_selector”

  27. android:layout_width=“wrap_content” android:layout_height=“wrap_content”

  28. android:layout_marginLeft=“12.0dip” android:layout_alignParentLeft=“true”

  29. android:layout_centerVertical=“true” />

  30. <Button android:id=“@+id/top_btn_right” android:textColor=“@color/button_text_selector”

  31. android:background=“@drawable/top_edit_selector” android:layout_width=“wrap_content”

  32. android:layout_height=“wrap_content” android:layout_marginRight=“12.0dip”

  33. android:layout_alignParentRight=“true” android:layout_centerVertical=“true” />

  34. <TextView android:id=“@+id/top_title” android:textSize=“22.0sp”

  35. android:textColor=“@color/head_line_text” android:ellipsize=“middle”

  36. android:gravity=“center_horizontal” android:layout_width=“wrap_content”

  37. android:layout_height=“wrap_content” android:text=“@string/user_name”

  38. android:singleLine=“true” android:layout_toLeftOf=“@id/top_btn_right”

  39. android:layout_toRightOf=“@id/top_btn_left”

  40. android:layout_centerInParent=“true”

  41. android:layout_alignWithParentIfMissing=“true” />

  42. </RelativeLayout>

总结

最后对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

、美团等公司2021年的面试题**,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

[外链图片转存中…(img-FgvaqmOa-1715355953586)]

[外链图片转存中…(img-mIgzjybk-1715355953587)]

当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 17
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值