您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。