Android怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果-創(chuàng)新互聯(lián)

本文小編為大家詳細(xì)介紹“Android怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“Android怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比小店網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式小店網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋小店地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。

抖音是一款音樂創(chuàng)意短視頻社交軟件,是一個(gè)專注年輕人的15秒音樂短視頻社區(qū)。用戶可以通過這款軟件選擇歌曲,拍攝15秒的音樂短視頻,形成自己的作品。此App已在Android各大應(yīng)用商店和APP Store均有上線。

在design包里面 有一個(gè) BottomSheetDialogFragment 這個(gè)Fragment,他已經(jīng)幫我們處理好了手勢(shì),所以實(shí)現(xiàn)起來很簡(jiǎn)單。下面是代碼:


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的高度設(shè)置為精確高度,即可屏蔽向上滑動(dòng)不占全屏的手勢(shì)。
  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;
  }
 }
}

補(bǔ)充:

Android SwipeRefreshLayout仿抖音app靜態(tài)刷新

SwipeRefreshLayout的功能就是可以讓我們的界面在不動(dòng)的情況下,下拉直接刷新

效果圖:

Android怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果

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怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞名稱:Android怎么實(shí)現(xiàn)仿抖音的評(píng)論列表UI效果-創(chuàng)新互聯(lián)
當(dāng)前URL:http://muchs.cn/article0/pepoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)公司、云服務(wù)器標(biāo)簽優(yōu)化、面包屑導(dǎo)航App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)