您好,登录后才能下订单哦!
本文小编为大家详细介绍“Android怎么实现仿抖音的评论列表UI效果”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android怎么实现仿抖音的评论列表UI效果”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
抖音是一款音乐创意短视频社交软件,是一个专注年轻人的15秒音乐短视频社区。用户可以通过这款软件选择歌曲,拍摄15秒的音乐短视频,形成自己的作品。此App已在Android各大应用商店和APP Store均有上线。
在design包里面 有一个 BottomSheetDialogFragment 这个Fragment,他已经帮我们处理好了手势,所以实现起来很简单。下面是代码:
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) { // 在这里将view的高度设置为精确高度,即可屏蔽向上滑动不占全屏的手势。 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<ViewHolder> { 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; } } }
补充:
Android SwipeRefreshLayout仿抖音app静态刷新
SwipeRefreshLayout的功能就是可以让我们的界面在不动的情况下,下拉直接刷新
效果图:
activity_listview布局文件
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/sr1" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="wrap_content"/> </android.support.v4.widget.SwipeRefreshLayout>
Activity代码(ListViewActivity)
public class ListViewActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout swipeRefreshLayout; private ListView listView; private List<String> 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); } }
读到这里,这篇“Android怎么实现仿抖音的评论列表UI效果”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。