List contactStrings = Arrays.asList(getResources().getStringArray(R.array.provinces));
List mobileStrings = Arrays.asList(getResources().getStringArray(R.array.provinces));
for (int i = 0; i < contactStrings.size(); i++) {
UserEntity contactEntity = new UserEntity(contactStrings.get(i), mobileStrings.get(i));
list.add(contactEntity);
}
return list;
}
}
Activity的.xml文件中:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“50dp”
android:orientation=“horizontal”
android:background=“@color/white”
android:elevation=“3dp”
<ImageView
android:id=“@+id/pic_contact_back”
android:layout_width=“50dp”
android:layout_height=“50dp”
android:src=“@drawable/back”
android:padding=“18dp”
/>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“城市选择”
android:layout_gravity=“center_vertical”
android:textColor=“@color/black”
android:textSize=“18sp”
/>
<me.yokeyword.indexablerv.IndexableLayout
android:id=“@+id/indexableLayout”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@android:color/white”
app:indexBar_selectedTextColor=“@color/black”
app:indexBar_textColor=“@color/gray1”
app:indexBar_layout_width=“40dp”
app:indexBar_textSize=“14sp”
app:indexBar_textSpace=“5dp” />
values
目录下的R.arrays.xml
城市资源文件:
上海
北京
杭州
广州
…
BannerHeaderAdapter
其实就是相当于IndexableLayout
的头布局,我这里的定位城市和热门城市就是通过添加这个头部(BannerHeaderAdapter
的item布局):
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:orientation=“vertical”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<TextView
android:layout_width=“match_parent”
android:layout_height=“40dp”
android:text=“定位城市”
android:gravity=“center_vertical”
android:paddingLeft=“15dp”
android:textSize=“@dimen/text_size_18”
android:textColor=“@color/black”
/>
<TextView
android:id=“@+id/item_header_city_dw”
android:layout_width=“80dp”
android:layout_height=“35dp”
android:textColor=“@color/black”
android:gravity=“center”
android:layout_marginLeft=“15dp”
android:background=“@drawable/sylayout_shop”
android:text=“东莞”/>
<View
android:layout_width=“match_parent”
android:layout_height=“1dp”
android:background=“@color/gray2”
android:layout_margin=“15dp”
/>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:paddingBottom=“5dp”
android:paddingLeft=“15dp”
android:paddingRight=“30dp”
android:orientation=“vertical”>
<TextView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:textSize=“18sp”
android:textColor=“@color/black”
android:text=“热门城市”/>
<com.wzg.biswang.util.QGridView
android:id=“@+id/item_header_city_gridview”
android:layout_marginTop=“5dp”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:focusable=“true”
android:focusableInTouchMode=“true”
android:numColumns=“3”
android:stretchMode=“columnWidth”
android:columnWidth=“60dp”
android:verticalSpacing=“10dp”
android:horizontalSpacing=“15dp”>
</com.wzg.biswang.util.QGridView>
<View
android:layout_width=“match_parent”
android:layout_height=“1dp”
android:background=“@color/gray2”
android:layout_marginLeft=“15dp”
android:layout_marginRight=“15dp”
android:layout_marginTop=“10dp”
/>
<TextView
android:layout_width=“match_parent”
android:layout_height=“50dp”
android:textSize=“18sp”
android:textColor=“@color/black”
android:layout_marginLeft=“15dp”
android:gravity=“center_vertical”
android:text=“所有城市”/>
ContactAdapter
的适配器也就是IndexableLayout的Adapter
,这里必须继承IndexableAdapter<UserEntity>
,你也可以直接把这段代码复制下来 :
public class ContactAdapter extends IndexableAdapter {
private LayoutInflater mInflater;
public ContactAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
//设置悬浮块的layout
@Override
public RecyclerView.ViewHolder onCreateTitleViewHolder(ViewGroup parent) {
View view = mInflater.inflate(R.layout.item_index_contact, parent, false);
return new IndexVH(view);
}
//设置悬浮块下面的layout
@Override
public RecyclerView.ViewHolder onCreateContentViewHolder(ViewGroup parent) {
View view = mInflater.inflate(R.layout.item_contact, parent, false);
return new ContentVH(view);
}
//设置悬浮块的数据
@Override
public void onBindTitleViewHolder(RecyclerView.ViewHolder holder, String indexTitle) {
IndexVH vh = (IndexVH) holder;
vh.tv.setText(indexTitle);
}
//设置悬浮块下面的数据
@Override
public void onBindContentViewHolder(RecyclerView.ViewHolder holder, UserEntity entity) {
ContentVH vh = (ContentVH) holder;
vh.tvName.setText(entity.getNick());
vh.tvMobile.setText(entity.getMobile());
}
private class IndexVH extends RecyclerView.ViewHolder {
TextView tv;
public IndexVH(View itemView) {
super(itemView);
tv = (TextView) itemView.findViewById(R.id.tv_index);
}
}
private class ContentVH extends RecyclerView.ViewHolder {
TextView tvName, tvMobile;
public ContentVH(View itemView) {
super(itemView);
tvName = (TextView) itemView.findViewById(R.id.tv_name);
tvMobile = (TextView) itemView.findViewById(R.id.tv_mobile);
}
}
}
悬浮块的xml文件:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<TextView
android:id=“@+id/tv_index”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“#f9f9f9”
android:paddingBottom=“8dp”
android:paddingLeft=“24dp”
android:paddingTop=“8dp”
android:textColor=“@color/gray”
android:text=“A”
android:textStyle=“bold”
android:textSize=“14sp” />
<ImageView
android:layout_width=“match_parent”
android:layout_height=“0.8dp”
android:background=“#f0f0f0” />
悬浮块下面的xml文件也就是item
布局:
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:paddingBottom=“5dp”
android:background=“?attr/selectableItemBackground”
android:paddingLeft=“16dp”
android:paddingRight=“16dp”
android:paddingTop=“5dp”>
<ImageView
android:visibility=“gone”
android:id=“@+id/img_avatar”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginRight=“16dp”
android:src=“@drawable/bsw_gray” />
<TextView
android:id=“@+id/tv_name”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_toRightOf=“@id/img_avatar”
tools:text=“张三”
android:textColor=“#373737”
android:textSize=“16sp” />
<TextView
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
学习分享
①「Android面试真题解析大全」PDF完整高清版+②「Android面试知识体系」学习思维导图压缩包——————可以点击我的【Github】免费下载,最后觉得有帮助、有需要的朋友可以点个赞
09704839)]
[外链图片转存中…(img-ngxf6d8X-1710509704839)]
[外链图片转存中…(img-MJzmFmSR-1710509704840)]
[外链图片转存中…(img-dxy2n9sz-1710509704840)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-I2bBGOcJ-1710509704841)]
学习分享
①「Android面试真题解析大全」PDF完整高清版+②「Android面试知识体系」学习思维导图压缩包——————可以点击我的【Github】免费下载,最后觉得有帮助、有需要的朋友可以点个赞
[外链图片转存中…(img-ClY8SgQK-1710509704841)]
[外链图片转存中…(img-FtT7f07l-1710509704842)]
[外链图片转存中…(img-OiYjyZuL-1710509704842)]