資源簡介
方便使用的評論工具類,而且能監聽到小鍵盤消失事件,能返回小鍵盤的高度,追蹤評論位置。
代碼片段和文件信息
package?com.zhrt.dp.duanpian.liver_plugin.danmu;
import?android.app.Activity;
import?android.content.Context;
import?android.graphics.drawable.BitmapDrawable;
import?android.os.Handler;
import?android.os.Message;
import?android.view.Gravity;
import?android.view.View;
import?android.view.ViewTreeObserver;
import?android.view.WindowManager;
import?android.view.inputmethod.InputMethodManager;
import?android.widget.Button;
import?android.widget.EditText;
import?android.widget.ListView;
import?android.widget.PopupWindow;
import?com.zhrt.dp.duanpian.R;
/**
?*?用來顯示聊天的布局,同時防止小鍵盤彈出導致播放內容高度的改變
?*?為了保證每次都能正確監聽小鍵盤的彈出與消失。pop不能復用,每次都要new哦
?*?Created?by?Eleven?on?2016/9/21.
?*/
public?class?TalkPopWindow?{
????public?TalkPopWindow(Activity?activity?OnSendMessage?onSendMessage){
????????this.activity?=?activity;
????????this.onSendMessage?=?onSendMessage;
????}
????/**
?????*?因為使用場景不同,所以這里可以用style標志來選取不同的布局,客官當然可以傳id
?????*?@param?activity
?????*?@param?onSendMessage
?????*?@param?style
?????*/
????public?TalkPopWindow(Activity?activity?OnSendMessage?onSendMessage?int?style){
????????this.activity?=?activity;
????????this.onSendMessage?=?onSendMessage;
????????this.style?=?style;
????}
????//入參
????Activity?activity;
????OnSendMessage?onSendMessage;
????//業務引用
????EditText?et;//通用輸入器
????Button?bt;//通用發送按鈕
????PopupWindow?pw;//popWindow??當然也可以換成dialog,popwindow:不會引起視頻的暫停等,但是沒有復制粘貼功能;dialog:會引起視頻的暫停,但是可以調起系統的復制粘貼功能
????int?style?=?0;//輸入部分樣式
????//View
????//兼容其他用途,設置syle
????View?view?=?null;//popView
????View?tempView?=?null;//輸入View的布局
????//邏輯屬性
????int?containerHeight?=?0;//tempView的高度:
????int?height?=?0;//布局的高度
????boolean?toShow?=?false;//是不是第一次嘗試顯示,與顯示機制有關
????int[]?location?=?new?int[2];
????/**
?????*?顯示pop
?????*/
????public?void?pop(){
????????dimiss();
????????toShow?=?true;
????????view?=?activity.getLayoutInflater().inflate(R.layout.pop_layoutnull);
????????pw?=?new?PopupWindow(view?WindowManager.LayoutParams.MATCH_PARENTWindowManager.LayoutParams.MATCH_PARENT);
????????if(style?==?0){//區分style
????????????et?=?(EditText)?view.findViewById(R.id.et_danmuEdit);
????????????bt?=?(Button)?view.findViewById(R.id.bt_sendDanmu);
????????????view.findViewById(R.id.danmutLinear).setVisibility(View.VISIBLE);
????????????view.findViewById(R.id.commentLinear).setVisibility(View.GONE);
????????????tempView?=?view.findViewById(R.id.danmutLinear);
????????}else{
????????????et?=?(EditText)?view.findViewById(R.id.commentEdit);
????????????bt?=?(Button)?view.findViewById(R.id.commentButton);
????????????view.findViewById(R.id.danmutLinear).setVisibility(View.GONE);
????????????view.findViewById(R.id.commentLinear).setVisibility(View.VISIBLE);
????????????tempView?=?view.findViewById(R.id.commentLinear);
????????}
????????tempView.measure(00);
????????containerHeight?=?tempView.getMeasuredHeight();//計算輸入布局的高度。
????????//監聽布局的變化
????????view.getViewTreeObserver
- 上一篇:網上求職招聘系統畢業設計
- 下一篇:Servlet API 中文版在線
評論
共有 條評論