關於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
相關文章
- vue 高仿微信即時 IM 聊天|仿微信 vue+h5 版|仿微信介面VueH5
- Android 仿微信/支付寶 字型大小 調整控制元件Android控制元件
- 仿微信錄音控制元件Demo控制元件
- android 關於先登入成功後再進入目標介面的思考Android
- 基於svelteKit開發仿微信app介面聊天例項APP
- 【Android】快速實現仿美團選擇城市介面,微信通訊錄介面Android
- 關於Android微信支付Android
- Android新增OpenCV支援,一步一步新增。AndroidOpenCV
- 仿微信評論控制元件封裝控制元件封裝
- Android 仿微信, QQ 裁剪Android
- Android仿微信介面--使用Fragment實現(慕課網筆記)AndroidFragment筆記
- Android 仿知乎分享控制元件Android控制元件
- nuxt.js仿微信App通訊聊天|vue+nuxt聊天|仿微信介面UXJSAPPVue
- 一個關於recyclerView的bugView
- android仿微信表情雨下落!Android
- iOS 給高仿微信新增直播聊天功能iOS
- 關於Android Studio使用Git的總結AndroidGit
- 基於 Flutter+Dart 仿微信 App 聊天應用|flutter 聊天介面FlutterDartAPP
- Android 高仿微信頭像擷取 打造不一樣的自定義控制元件Android控制元件
- 5.Android(RecyclerView控制元件總結)AndroidView控制元件
- iOS UIWebview仿微信進度條iOSUIWebView
- Android RecyclerView 通用介面卡的實現AndroidView
- electron+vue 仿微信客戶端聊天|electron 仿微信介面|electron 聊天例項Vue客戶端
- Android 給RecyclerView新增頭部和尾部AndroidView
- 基於Flutter的仿微信聊天應用Flutter
- 基於 Flutter+Dart 聊天例項 | Flutter 仿微信介面聊天室FlutterDart
- 關於CAD夢想控制元件介面控制控制元件
- Android ActionBar應用實戰,高仿微信主介面的設計Android
- 關於RecyclerView.ItemDecoration的自定義View
- Android Studio微信頁面Android
- 關於 一合相 的再進一步的理解。
- 仿房產銷冠APP銷控表介面-多RecyclerView同步滾動APPView
- 如何實現仿微信介面[我的+首頁聊天列表+長按選單功能+新增選單功能]
- 【Android進階】RecyclerView之ItemDecoration(一)AndroidView
- 智慧聊天機器人原始碼—仿微信介面機器人原始碼
- Android中RecyclerView用法,一步一步教你如何使用RecyclerView以及帶你走過編碼中可能會出現的坑~AndroidView
- (轉) Android 優雅的為RecyclerView新增HeaderView和FooterViewAndroidViewHeader
- RecyclerView - 新增不同的分割線View