Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve the UI effect of imitating Douyin's comment list by Android

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how Android achieves the UI effect of imitating Douyin's comment list". The content is detailed, the steps are clear, and the details are handled properly. I hope this "Android how to achieve UI effect of imitating Douyin's comment list" article can help you solve your doubts.

Douyin is a music creative short video social software, is a 15-second music short video community focusing on young people. Through this software, users can select songs and shoot 15-second short music videos to form their own works. This App has been launched in all Android app stores and APP Store.

There is a BottomSheetDialogFragment Fragment in the design package. He has handled the gestures for us, so it is very easy to implement. Here is the code:

Public class ItemListDialogFragment extends BottomSheetDialogFragment {/ / TODO: Customize parameter argument names private static final String ARG_ITEM_COUNT = "item_count"; private Listener mListener; / / TODO: Customize parameters public static ItemListDialogFragment newInstance (int itemCount) {final ItemListDialogFragment fragment = new ItemListDialogFragment (); final Bundle args = new Bundle (); args.putInt (ARG_ITEM_COUNT, itemCount); fragment.setArguments (args); return fragment } @ Nullable @ Override public View onCreateView (LayoutInflater inflater, @ Nullable ViewGroup container, @ Nullable Bundle savedInstanceState) {/ / set the height of the view to the exact height here to block gestures that slide upward and do not occupy the full screen. View view = inflater.inflate (R.layout.fragment_item_list_dialog, container, false); view.setLayoutParams (new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MATCH_PARENT, ScreenUtils.getScreenHeight (getActivity ()) / 3 * 2)); return view;} @ Override public void onViewCreated (View view, @ Nullable Bundle savedInstanceState) {final RecyclerView recyclerView = (RecyclerView) view; recyclerView.setLayoutManager (new LinearLayoutManager (getContext (); recyclerView.setAdapter (new ItemAdapter (getArguments (). GetInt (ARG_ITEM_COUNT) } @ Override public void onAttach (Context context) {super.onAttach (context); final Fragment parent = getParentFragment (); if (parent! = null) {mListener = (Listener) parent;} else {mListener = (Listener) context;}} @ Override public void onDetach () {mListener = null; super.onDetach ();} public interface Listener {void onItemClicked (int position);} private class ViewHolder extends RecyclerView.ViewHolder {final TextView text ViewHolder (LayoutInflater inflater, ViewGroup parent) {/ / TODO: Customize the item layout super (inflater.inflate (R.layout.fragment_item_list_dialog_item, parent, false); text = (TextView) itemView.findViewById (R.id.text); text.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (mListener! = null) {mListener.onItemClicked (getAdapterPosition ()); dismiss () Private class ItemAdapter extends RecyclerView.Adapter {private final int mItemCount; ItemAdapter (int itemCount) {mItemCount = itemCount;} @ Override public ViewHolder onCreateViewHolder (ViewGroup parent, int viewType) {return new ViewHolder (LayoutInflater.from (parent.getContext ()), parent);} @ Override public void onBindViewHolder (ViewHolder holder, int position) {holder.text.setText (String.valueOf (position));} @ Override public int getItemCount () {return mItemCount;}

Add:

Android SwipeRefreshLayout imitating Douyin app static refresh

The function of SwipeRefreshLayout is to refresh our interface directly without moving.

Effect picture:

Activity_listview layout file

Activity Code (ListViewActivity)

Public class ListViewActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {private SwipeRefreshLayout swipeRefreshLayout; private ListView listView; private List list; private ArrayAdapter adapter; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_list_view); swipeRefreshLayout = (SwipeRefreshLayout) findViewById (R.id.sr1); swipeRefreshLayout.setOnRefreshListener (this); list = new ArrayList (); list.add ("ssss"); listView = (ListView) findViewById (R.id.lv) Adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, android.R.id.text1, list); listView.setAdapter (adapter);} @ Override public void onRefresh () {new Handler () .postDelayed (new Runnable () {@ Override public void run () {swipeRefreshLayout.setRefreshing (false); adapter.clear () List.add ("1111"); adapter.notifyDataSetChanged ();}}, 1000);}} read this, the article "how Android achieves the UI effect of imitating Douyin's comment list" has been introduced, and if you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about the article, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report