關於AS(Android studio)新增recyclerview控制元件後的進一步仿微信介面
關於AS(Android studio)新增recyclerview控制元件後的進一步仿微信介面
要求:在原有基礎上新增recyclerview佈局
實現頁面展示:
相比較上次,我們新增了刪除資訊,分類和隱藏縮放的功能。
因此我們需要更新一下我們上次佈局裡的三個xml檔案tab01,tab02,tab03。
分別各自新增一個recyclerview的控制元件,再分別修改一下id等引數。
然後是Java程式碼檔案裡對應的三個Fragment也需要更新。
weixinFragment:
package com.example.Mywechat;
import ...
/**
* A simple {@link Fragment} subclass.
*/
public class weixinFragment extends Fragment {
private RecyclerView recyclerView;
private List<String> mList = new ArrayList<>();
private Context context;
private adapter_swipe adapter;
public weixinFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.tab01, container, false);
recyclerView=view.findViewById(R.id.rcvone);
initData();
initView();
return view;
}
private void initData() {
mList.add("Optimus Prime");
mList.add("Blaster ");
mList.add("Perceptor");
mList.add("Hound");
mList.add("Jazz");
mList.add("Prowl");
mList.add("Ratchet ");
mList.add("Wheeljack");
mList.add("Bluestreak");
mList.add("Mirage");
mList.add("Sideswipe");
mList.add("Trailbreaker");
mList.add("Sunstreaker");
mList.add("Grapple");
mList.add("Hoist");
mList.add("Inferno");
mList.add("Red Alert");
mList.add("Smokescreen");
mList.add("Tracks");
mList.add("Skids");
mList.add("Megatron");
mList.add("STARSCREAM");
mList.add("Barricade");
mList.add("Bonecrusher");
mList.add("Brawl");
mList.add("Blackout");
mList.add("Scorponok");
mList.add("Frenzy");
mList.add("The Fallen");
mList.add("Alice");
mList.add("Devastator");
mList.add("Mixmaster");
mList.add("Hightower");
mList.add("Rampage");
mList.add("Scrapper");
mList.add("Longhaul");
mList.add("Demolisher");
mList.add("Sideways");
mList.add("Grindor");
mList.add("Soundwave");
}
private void initView(){
context=this.getActivity();
adapter=new adapter_swipe(context,mList);
ItemTouchHelper.Callback callback = new SwipeItemTouchHelper(adapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(recyclerView);
LinearLayoutManager manager=new LinearLayoutManager(context);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
}
}
FrdFragment:
package com.example.Mywechat;
import ...
/**
* A simple {@link Fragment} subclass.
*/
public class frdFragment extends Fragment {
private static final String TAG = frdFragment.class.getSimpleName();
private RecyclerView recyclerView;
private TextView tvArea;
private List<String> mList = new ArrayList<>();
private List<StickyData> mDataList = new ArrayList<>();
private Context context;
private adapter adapter;
public frdFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.tab02, container, false);
recyclerView=view.findViewById(R.id.rcvtwo);
tvArea=view.findViewById(R.id.tv_sticky_header_view);
initList();
initData();
initView();
return view;
}
private void initList() {
mList.add("博派|Optimus Prime");
mList.add("博派|Blaster ");
mList.add("博派|Perceptor");
mList.add("博派|Hound");
mList.add("博派|Jazz");
mList.add("博派|Prowl");
mList.add("博派|Ratchet ");
mList.add("博派|Wheeljack");
mList.add("博派|Bluestreak");
mList.add("博派|Mirage");
mList.add("博派|Sideswipe");
mList.add("博派|Trailbreaker");
mList.add("博派|Sunstreaker");
mList.add("博派|Grapple");
mList.add("博派|Hoist");
mList.add("博派|Inferno");
mList.add("博派|Red Alert");
mList.add("博派|Smokescreen");
mList.add("博派|Tracks");
mList.add("博派|Skids");
mList.add("狂派|Megatron");
mList.add("狂派|STARSCREAM");
mList.add("狂派|Barricade");
mList.add("狂派|Bonecrusher");
mList.add("狂派|Brawl");
mList.add("狂派|Blackout");
mList.add("狂派|Scorponok");
mList.add("狂派|Frenzy");
mList.add("狂派|The Fallen");
mList.add("狂派|Alice");
mList.add("狂派|Devastator");
mList.add("狂派|Mixmaster");
mList.add("狂派|Hightower");
mList.add("狂派|Rampage");
mList.add("狂派|Scrapper");
mList.add("狂派|Longhaul");
mList.add("狂派|Demolisher");
mList.add("狂派|Sideways");
mList.add("狂派|Grindor");
mList.add("狂派|Soundwave");
}
private void initData() {
for (int i = 0; i < mList.size(); i++) {
StickyData bean = new StickyData();
String s = mList.get(i);
// area
String area = s.substring(0, s.indexOf("|"));
// team
String team = s.substring(s.indexOf("|") + 1, s.length());
bean.setArea(area);
bean.setTeam(team);
mDataList.add(bean);
}
Log.d(TAG, "initData: " + mDataList.size());
}
private void initView() {
context=this.getActivity();
adapter=new adapter(context,mDataList);
LinearLayoutManager manager=new LinearLayoutManager(context);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
View stickyInfoView = recyclerView.findChildViewUnder(
tvArea.getMeasuredWidth() / 2, 5);
if (stickyInfoView != null && stickyInfoView.getContentDescription() != null) {
tvArea.setText(String.valueOf(stickyInfoView.getContentDescription()));
}
View transInfoView = recyclerView.findChildViewUnder(
tvArea.getMeasuredWidth() / 2, tvArea.getMeasuredHeight() + 1);
if (transInfoView != null && transInfoView.getTag() != null) {
int transViewStatus = (int) transInfoView.getTag();
int dealtY = transInfoView.getTop() - tvArea.getMeasuredHeight();
if (transViewStatus == adapter.HAS_STICKY_VIEW) {
if (transInfoView.getTop() > 0) {
tvArea.setTranslationY(dealtY);
} else {
tvArea.setTranslationY(0);
}
} else if (transViewStatus == adapter.NONE_STICKY_VIEW) {
tvArea.setTranslationY(0);
}
}
}
});
}
}
contentFragment:
package com.example.Mywechat;
import ...
/**
* A simple {@link Fragment} subclass.
*/
public class contactFragment extends Fragment {
private RecyclerView recyclerView;
private List<String> mList = new ArrayList<>();
private Context context;
private adapter_expand adapter;
public contactFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.tab03, container, false);
recyclerView=view.findViewById(R.id.rcvthere);
initexpandData();
initView();
return view;
}
private void initexpandData(){
mList.add("Optimus Prime");
mList.add("Blaster ");
mList.add("Perceptor");
mList.add("Hound");
mList.add("Jazz");
mList.add("Prowl");
mList.add("Ratchet ");
mList.add("Wheeljack");
mList.add("Bluestreak");
mList.add("Mirage");
mList.add("Sideswipe");
mList.add("Trailbreaker");
mList.add("Sunstreaker");
mList.add("Grapple");
mList.add("Hoist");
mList.add("Inferno");
mList.add("Red Alert");
mList.add("Smokescreen");
mList.add("Tracks");
mList.add("Skids");
mList.add("Megatron");
mList.add("STARSCREAM");
mList.add("Barricade");
mList.add("Bonecrusher");
mList.add("Brawl");
mList.add("Blackout");
mList.add("Scorponok");
mList.add("Frenzy");
mList.add("The Fallen");
mList.add("Alice");
mList.add("Devastator");
mList.add("Mixmaster");
mList.add("Hightower");
mList.add("Rampage");
mList.add("Scrapper");
mList.add("Longhaul");
mList.add("Demolisher");
mList.add("Sideways");
mList.add("Grindor");
mList.add("Soundwave");
}
private void initView(){
context=this.getActivity();
adapter=new adapter_expand(context,mList);
LinearLayoutManager manager=new LinearLayoutManager(context);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
}
}
參考網址:https://www.jianshu.com/p/c4cfe38a91ed
https://developer.android.google.cn/guide/topics/ui/layout/recyclerview#java
原始碼已經上傳到gitee:https://gitee.com/milk-sugar-is-not-sweet/as/blob/master/Myweat%20Recyclerview/Myweat%20Recyclerview.rar
相關文章
- Android 仿微信/支付寶 字型大小 調整控制元件Android控制元件
- Android 仿微信, QQ 裁剪Android
- vue 高仿微信即時 IM 聊天|仿微信 vue+h5 版|仿微信介面VueH5
- Android Studio微信頁面Android
- android仿微信表情雨下落!Android
- 仿微信評論控制元件封裝控制元件封裝
- 基於svelteKit開發仿微信app介面聊天例項APP
- nuxt.js仿微信App通訊聊天|vue+nuxt聊天|仿微信介面UXJSAPPVue
- electron+vue 仿微信客戶端聊天|electron 仿微信介面|electron 聊天例項Vue客戶端
- 基於 Flutter+Dart 仿微信 App 聊天應用|flutter 聊天介面FlutterDartAPP
- 基於Flutter的仿微信聊天應用Flutter
- 關於Android Studio使用Git的總結AndroidGit
- 5.Android(RecyclerView控制元件總結)AndroidView控制元件
- Android新增OpenCV支援,一步一步新增。AndroidOpenCV
- Android 仿微信的圖片選擇器ImageSelector的使用Android
- 基於 Flutter+Dart 聊天例項 | Flutter 仿微信介面聊天室FlutterDart
- HarmonyOS 5.0應用開發——仿微信聊天介面
- Svelte3-Chat:基於svelte+svelteKit+sass仿微信聊天例項|svelte仿微信
- Android 仿釘釘、微信 群聊組合頭像Android
- 如何實現仿微信介面[我的+首頁聊天列表+長按選單功能+新增選單功能]
- 高仿微信聊天介面長按彈框樣式
- 微信圈圈 - 關於微信那點事
- Android側滑返回分析和實現(不高仿微信)Android
- 基於微信小程式的知乎介面微信小程式
- 關於CAD夢想控制元件介面控制控制元件
- 【Android進階】RecyclerView之ItemDecoration(一)AndroidView
- react 實戰開發|react+redux 仿微信聊天介面ReactRedux
- svelte-webchat:基於Svelte3+SvelteKit仿微信Mac網頁介面聊天例項WebMac網頁
- 關於 Android studio 在xml中不提示的問題AndroidXML
- 微信app支付 java後臺接AndroidAPPJavaAndroid
- MUKeyboard(仿微信鍵盤)
- ReactNative 聊天 App 實戰|RN 仿微信介面群聊|朋友圈ReactAPP
- 關於RecyclerView.ItemDecoration的自定義View
- 【Android進階】RecyclerView之快取(二)AndroidView快取
- Android 微信分享後留在微信,沒有回撥的問題解決方案Android
- Android中RecyclerView用法,一步一步教你如何使用RecyclerView以及帶你走過編碼中可能會出現的坑~AndroidView
- Android中的RecyclerViewAndroidView
- Android Studio中的一些常見控制元件Android控制元件