抖音是一款音乐创意短视频社交软件,是一个专注年轻人的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和效果的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
您可能感兴趣的文章:Android SwipeRefreshLayout仿抖音app静态刷新 总结以上是内存溢出为你收集整理的Android 仿抖音的评论列表的UI和效果的实现代码全部内容,希望文章能够帮你解决Android 仿抖音的评论列表的UI和效果的实现代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)