最后
这里我特地整理了一份《Android开发核心知识点笔记》,里面就包含了自定义View相关的内容
除了这份笔记,还给大家分享 Android学习PDF+架构视频+面试文档+源码笔记,高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料这几块的内容。非常适合近期有面试和想在技术道路上继续精进的朋友。
分享上面这些资源,希望可以帮助到大家提升进阶,如果你觉得还算有用的话,不妨把它们推荐给你的朋友~
喜欢本文的话,给我点个小赞、评论区留言或者转发支持一下呗~
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
tabHost = getTabHost();
-
populateTab();
-
}
-
/**
-
* 组装tab控件
-
*/
-
private void populateTab() {
-
Resources res = getResources();
-
populateTabItem(R.drawable.tab_home_selector,
-
res.getString(R.string.tab_home), new Intent(this,
-
HomeActivity.class));
-
populateTabItem(R.drawable.tab_atme_selector,
-
res.getString(R.string.tab_refer), new Intent(this,
-
ReferActivity.class));
-
populateTabItem(R.drawable.tab_message_selector,
-
res.getString(R.string.tab_secret), new Intent(this,
-
MessageActivity.class));
-
populateTabItem(R.drawable.tab_explore_selector,
-
res.getString(R.string.tab_search), new Intent(this,
-
SearchActivity.class));
-
populateTabItem(R.drawable.tab_focus_selector,
-
res.getString(R.string.tab_attention), new Intent(this,
-
AttentionActivity.class));
-
}
-
/**
-
* 生成tab_item
-
*
-
* @param imageResourceSelector
-
* 图片选择器
-
* @param text
-
* 文本
-
* @param intent
-
* intent
-
*/
-
private void populateTabItem(int imageResourceSelector, String text,
-
Intent intent) {
-
View view = View.inflate(this, R.layout.tab_item, null);// 拼装view
-
((ImageView) view.findViewById(R.id.tab_item_imageview))
-
.setImageResource(imageResourceSelector);
-
((TextView) view.findViewById(R.id.tab_item_textview)).setText(text);
-
TabSpec spec = tabHost.newTabSpec(text).setIndicator(view)
-
.setContent(intent);// 将view注入spec
-
tabHost.addTab(spec);
-
}
-
}
-
public class MainActivity extends TabActivity {
-
private TabHost tabHost;
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
tabHost = getTabHost();
-
populateTab();
-
}
-
/**
-
* 组装tab控件
-
*/
-
private void populateTab() {
-
Resources res = getResources();
-
populateTabItem(R.drawable.tab_home_selector,
-
res.getString(R.string.tab_home), new Intent(this,
-
HomeActivity.class));
-
populateTabItem(R.drawable.tab_atme_selector,
-
res.getString(R.string.tab_refer), new Intent(this,
-
ReferActivity.class));
-
populateTabItem(R.drawable.tab_message_selector,
-
res.getString(R.string.tab_secret), new Intent(this,
-
MessageActivity.class));
-
populateTabItem(R.drawable.tab_explore_selector,
-
res.getString(R.string.tab_search), new Intent(this,
-
SearchActivity.class));
-
populateTabItem(R.drawable.tab_focus_selector,
-
res.getString(R.string.tab_attention), new Intent(this,
-
AttentionActivity.class));
-
}
-
/**
-
* 生成tab_item
-
*
-
* @param imageResourceSelector
-
* 图片选择器
-
* @param text
-
* 文本
-
* @param intent
-
* intent
-
*/
-
private void populateTabItem(int imageResourceSelector, String text,
-
Intent intent) {
-
View view = View.inflate(this, R.layout.tab_item, null);// 拼装view
-
((ImageView) view.findViewById(R.id.tab_item_imageview))
-
.setImageResource(imageResourceSelector);
-
((TextView) view.findViewById(R.id.tab_item_textview)).setText(text);
-
TabSpec spec = tabHost.newTabSpec(text).setIndicator(view)
-
.setContent(intent);// 将view注入spec
-
tabHost.addTab(spec);
-
}
-
}
Xml代码
- <?xml version\="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”>
-
<RelativeLayout android:orientation=“vertical”
-
android:layout_width=“fill_parent” android:layout_height=“fill_parent”>
-
<include android:id=“@+id/head_line” layout=“@layout/head_line”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content” />
-
<FrameLayout android:id=“@android:id/tabcontent”
-
android:layout_below=“@id/head_line” android:layout_width=“fill_parent”
-
android:layout_height=“fill_parent” android:layout_weight=“1.0” />
-
<TabWidget android:id=“@android:id/tabs” android:background=“@drawable/tab_bkg”
-
android:layout_gravity=“bottom” android:layout_height=“60.0dip”
-
android:layout_width=“fill_parent” android:fadingEdge=“none”
-
android:fadingEdgeLength=“0.0px” android:paddingLeft=“0.0dip”
-
android:paddingTop=“2.0dip” android:paddingRight=“0.0dip”
-
android:paddingBottom=“0.0dip” android:layout_alignParentBottom=“true”
-
android:layout_alignParentTop=“false” />
-
</RelativeLayout>
-
</TabHost>
- <?xml version\="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”>
-
<RelativeLayout android:orientation=“vertical”
-
android:layout_width=“fill_parent” android:layout_height=“fill_parent”>
-
<include android:id=“@+id/head_line” layout=“@layout/head_line”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content” />
-
<FrameLayout android:id=“@android:id/tabcontent”
-
android:layout_below=“@id/head_line” android:layout_width=“fill_parent”
-
android:layout_height=“fill_parent” android:layout_weight=“1.0” />
-
<TabWidget android:id=“@android:id/tabs” android:background=“@drawable/tab_bkg”
-
android:layout_gravity=“bottom” android:layout_height=“60.0dip”
-
android:layout_width=“fill_parent” android:fadingEdge=“none”
-
android:fadingEdgeLength=“0.0px” android:paddingLeft=“0.0dip”
-
android:paddingTop=“2.0dip” android:paddingRight=“0.0dip”
-
android:paddingBottom=“0.0dip” android:layout_alignParentBottom=“true”
-
android:layout_alignParentTop=“false” />
-
</RelativeLayout>
-
</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代码
-
<include android:id=“@+id/head_line” layout=“@layout/head_line”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content” />
view plain copy to clipboard print ?
-
<include android:id=“@+id/head_line” layout=“@layout/head_line”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content” />
作用是引入另一个View文件,head_line.xml
Xml代码
-
<RelativeLayout android:background=“@drawable/header”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content”
-
xmlns:android=“http://schemas.android.com/apk/res/android”>
-
<Button android:id=“@+id/top_btn_left” android:textColor=“@color/button_text_selector”
-
android:background=“@drawable/top_refresh_selector”
-
android:layout_width=“wrap_content” android:layout_height=“wrap_content”
-
android:layout_marginLeft=“12.0dip” android:layout_alignParentLeft=“true”
-
android:layout_centerVertical=“true” />
-
<Button android:id=“@+id/top_btn_right” android:textColor=“@color/button_text_selector”
-
android:background=“@drawable/top_edit_selector” android:layout_width=“wrap_content”
-
android:layout_height=“wrap_content” android:layout_marginRight=“12.0dip”
-
android:layout_alignParentRight=“true” android:layout_centerVertical=“true” />
-
<TextView android:id=“@+id/top_title” android:textSize=“22.0sp”
-
android:textColor=“@color/head_line_text” android:ellipsize=“middle”
-
android:gravity=“center_horizontal” android:layout_width=“wrap_content”
-
android:layout_height=“wrap_content” android:text=“@string/user_name”
-
android:singleLine=“true” android:layout_toLeftOf=“@id/top_btn_right”
-
android:layout_toRightOf=“@id/top_btn_left”
-
android:layout_centerInParent=“true”
-
android:layout_alignWithParentIfMissing=“true” />
-
</RelativeLayout>
-
<RelativeLayout android:background=“@drawable/header”
-
android:layout_width=“fill_parent” android:layout_height=“wrap_content”
-
xmlns:android=“http://schemas.android.com/apk/res/android”>
-
<Button android:id=“@+id/top_btn_left” android:textColor=“@color/button_text_selector”
-
android:background=“@drawable/top_refresh_selector”
-
android:layout_width=“wrap_content” android:layout_height=“wrap_content”
-
android:layout_marginLeft=“12.0dip” android:layout_alignParentLeft=“true”
-
android:layout_centerVertical=“true” />
-
<Button android:id=“@+id/top_btn_right” android:textColor=“@color/button_text_selector”
-
android:background=“@drawable/top_edit_selector” android:layout_width=“wrap_content”
-
android:layout_height=“wrap_content” android:layout_marginRight=“12.0dip”
-
android:layout_alignParentRight=“true” android:layout_centerVertical=“true” />
-
<TextView android:id=“@+id/top_title” android:textSize=“22.0sp”
-
android:textColor=“@color/head_line_text” android:ellipsize=“middle”
-
android:gravity=“center_horizontal” android:layout_width=“wrap_content”
-
android:layout_height=“wrap_content” android:text=“@string/user_name”
-
android:singleLine=“true” android:layout_toLeftOf=“@id/top_btn_right”
-
android:layout_toRightOf=“@id/top_btn_left”
-
android:layout_centerInParent=“true”
-
android:layout_alignWithParentIfMissing=“true” />
-
</RelativeLayout>
总结
最后对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!
这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
相信它会给大家带来很多收获:
当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
、美团等公司2021年的面试题**,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
相信它会给大家带来很多收获:
[外链图片转存中…(img-FgvaqmOa-1715355953586)]
[外链图片转存中…(img-mIgzjybk-1715355953587)]
当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!