最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿微信實(shí)現(xiàn)評(píng)論功能

 更新時(shí)間:2018年11月28日 10:29:51   作者:Ls雙兒  
這篇文章主要為大家詳細(xì)介紹了Android仿微信實(shí)現(xiàn)評(píng)論功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在最近做的項(xiàng)目中有碰到要寫類似朋友圈的模塊,因?yàn)橐獙?shí)現(xiàn)評(píng)論點(diǎn)贊功能,這里說下我是怎么實(shí)現(xiàn)評(píng)論功能的。

首先先放上效果圖  

這里貼上我的代碼:

//給評(píng)論圖標(biāo)設(shè)置點(diǎn)擊事件
 mIv_header_discuss.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  showPopupcomment();
  }
 });

showPopupcomment()方法如下

private PopupWindow popupWindow;
 private View popupView = null;
 private EditText inputComment;
 private String nInputContentText;
 private TextView btn_submit;
 private RelativeLayout rl_input_container;
 private InputMethodManager mInputManager;
 @SuppressLint("WrongConstant")
 private void showPopupcomment() {
 if (popupView == null){
 //加載評(píng)論框的資源文件 
  popupView = LayoutInflater.from(context).inflate(R.layout.comment_popupwindow, null);
 }
 inputComment = (EditText) popupView.findViewById(R.id.et_discuss);
 btn_submit = (Button) popupView.findViewById(R.id.btn_confirm);
 rl_input_container = (RelativeLayout)popupView.findViewById(R.id.rl_input_container);
 //利用Timer這個(gè)Api設(shè)置延遲顯示軟鍵盤,這里時(shí)間為200毫秒
 Timer timer = new Timer();
 timer.schedule(new TimerTask() {

  public void run()
  {
  mInputManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
  mInputManager.showSoftInput(inputComment, 0);
  }

 }, 200);
 if (popupWindow == null){
  popupWindow = new PopupWindow(popupView, RelativeLayout.LayoutParams.MATCH_PARENT,
   RelativeLayout.LayoutParams.WRAP_CONTENT, false);

 }
 //popupWindow的常規(guī)設(shè)置,設(shè)置點(diǎn)擊外部事件,背景色
 popupWindow.setTouchable(true);
 popupWindow.setFocusable(true);
 popupWindow.setOutsideTouchable(true);
 popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
 popupWindow.setTouchInterceptor(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
   popupWindow.dismiss();
  return false;

  }
 });

 // 設(shè)置彈出窗體需要軟鍵盤,放在setSoftInputMode之前
 popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
 // 再設(shè)置模式,和Activity的一樣,覆蓋,調(diào)整大小。
 popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
 //設(shè)置popupwindow的顯示位置,這里應(yīng)該是顯示在底部,即Bottom
 popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0);

 popupWindow.update();

 //設(shè)置監(jiān)聽
 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

  // 在dismiss中恢復(fù)透明度
  @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
  public void onDismiss() {

  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(), 0); //強(qiáng)制隱藏鍵盤


  }
 });
 //外部點(diǎn)擊事件
 rl_input_container.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {


  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(), 0); //強(qiáng)制隱藏鍵盤
  popupWindow.dismiss();

  }
 });
 //評(píng)論框內(nèi)的發(fā)送按鈕設(shè)置點(diǎn)擊事件
 btn_submit.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {


  nInputContentText = inputComment.getText().toString().trim();

  if (nInputContentText == null || "".equals(nInputContentText)) {
   showToastMsgShort("請(qǐng)輸入評(píng)論內(nèi)容");
   return;
  }
  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(),0);
  popupWindow.dismiss();

  }
 });
 }

在剛開始顯示的時(shí)候發(fā)現(xiàn),EditText即評(píng)論框被頂?shù)狡聊蛔钌戏剑欢I盤顯示在底部,達(dá)不到效果。很多文章都說

popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

這兩句代碼順序不能變,然而這樣寫了之后還是實(shí)現(xiàn)不了,自己摸索了半天發(fā)現(xiàn)出現(xiàn)這樣的問題與評(píng)論框的布局也有關(guān)系。

所以在這里貼上我的評(píng)論框布局

R.layout.comment_popupwindow

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/rl_input_container"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="44dp"
  android:background="@color/colorWhite"
  android:layout_alignParentBottom="true"
  android:orientation="horizontal">
  <EditText
  android:id="@+id/et_discuss"
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="38dp"
  android:textColorHint="#a2a2a2"
  android:textSize="13sp"
  android:layout_marginRight="7dp"
  android:layout_marginLeft="15dp"
  android:layout_marginBottom="6dp"
  android:layout_marginTop="6dp"
  android:ellipsize="end"
  android:background="@drawable/round_edittext_input"
  android:layout_gravity="center_vertical"
  android:paddingLeft="@dimen/ten_padding"
  android:paddingRight="@dimen/ten_padding"
  android:singleLine="true" />
  <Button
  android:id="@+id/btn_confirm"
  android:text="發(fā)送"
  android:background="@drawable/btn_discuss_bg"
  android:textSize="16sp"
  android:layout_gravity="center_vertical"
  android:textColorHint="#b7b7b7"
  android:textColor="@color/colorWhite"
  android:layout_marginRight="@dimen/ten_padding"
  android:gravity="center"
  android:layout_width="40dp"
  android:layout_height="38dp"/>
  </LinearLayout>
</RelativeLayout>

把評(píng)論框和發(fā)送按鈕用LinearLayout包裹,然后在最外層用一個(gè)RelativeLayout包裹住,發(fā)現(xiàn)這樣子評(píng)論框就會(huì)和軟鍵盤一起彈出來了。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android實(shí)現(xiàn)始終顯示overflow菜單的方法

    android實(shí)現(xiàn)始終顯示overflow菜單的方法

    這篇文章主要介紹了android實(shí)現(xiàn)始終顯示overflow菜單的方法,需要的朋友可以參考下
    2014-07-07
  • Android自定義View實(shí)現(xiàn)五星好評(píng)效果

    Android自定義View實(shí)現(xiàn)五星好評(píng)效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)五星好評(píng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android圖片識(shí)別應(yīng)用詳解

    Android圖片識(shí)別應(yīng)用詳解

    這篇文章主要為大家詳細(xì)介紹了Android圖片識(shí)別的應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)的圖片頭像控件

    Android實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)的圖片頭像控件

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶有動(dòng)態(tài)圓環(huán)的圓形圖片控件DynamicAvatarView的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android判斷登錄情況

    Android判斷登錄情況

    這篇文章主要介紹了Android判斷登錄情況,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Android仿今日頭條滑動(dòng)頁面導(dǎo)航效果

    Android仿今日頭條滑動(dòng)頁面導(dǎo)航效果

    這篇文章主要為大家詳細(xì)介紹了Android仿今日頭條滑動(dòng)頁面導(dǎo)航效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android自定義View弧線進(jìn)度控件

    Android自定義View弧線進(jìn)度控件

    這篇文章主要為大家詳細(xì)介紹了Android自定義View弧線進(jìn)度控件,點(diǎn)擊開始按鈕時(shí),逐漸的出現(xiàn)進(jìn)度,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android如何使用圓形揭露動(dòng)畫巧妙地隱藏或顯示View詳解

    Android如何使用圓形揭露動(dòng)畫巧妙地隱藏或顯示View詳解

    Android開發(fā)中會(huì)遇到不少顯示和隱藏的問題,下面這篇文章主要給大家介紹了關(guān)于Android如何使用圓形揭露動(dòng)畫巧妙地隱藏或顯示View的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • Android 7.0中新簽名對(duì)多渠道打包的影響詳解

    Android 7.0中新簽名對(duì)多渠道打包的影響詳解

    這篇文章主要介紹了Android 7.0中新簽名對(duì)多渠道打包的影響,文中介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • Android自定義View實(shí)現(xiàn)掃描效果

    Android自定義View實(shí)現(xiàn)掃描效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)掃描效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04

最新評(píng)論

白玉县| 中西区| 县级市| 绥阳县| 馆陶县| 青阳县| 中阳县| 玉门市| 通道| 安宁市| 会昌县| 深州市| 思茅市| 巩义市| 会泽县| 博兴县| 会理县| 盐山县| 巴彦县| 乌兰浩特市| 华安县| 宜宾市| 澎湖县| 乐安县| 永寿县| 闸北区| 孝昌县| 凌云县| 许昌市| 巴东县| 吉首市| 建湖县| 乡宁县| 兴仁县| 霸州市| 千阳县| 教育| 额尔古纳市| 南城县| 辽中县| 洪雅县|