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

Android實(shí)現(xiàn)表情功能

 更新時(shí)間:2022年04月01日 10:35:50   作者:qq_21467035  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)表情功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)表情功能的具體代碼,供大家參考,具體內(nèi)容如下

Dialog實(shí)現(xiàn)表情評(píng)論功能核心問題:

1、如何得到鍵盤彈起和隱藏狀態(tài)
2、在于表情和鍵盤切換時(shí)候,防止Dialog抖動(dòng)

問題1:由于無(wú)法獲取鍵盤彈起狀態(tài),但是鍵盤彈起,View尺寸變化,同時(shí)被onSizeChanged()調(diào)用。

View 源碼:

/**
? ? ?* This is called during layout when the size of this view has changed. If
? ? ?* you were just added to the view hierarchy, you're called with the old
? ? ?* values of 0.
? ? ?*
? ? ?* @param w Current width of this view.
? ? ?* @param h Current height of this view.
? ? ?* @param oldw Old width of this view.
? ? ?* @param oldh Old height of this view.
? ? ?*/
? ? protected void onSizeChanged(int w, int h, int oldw, int oldh) {
}

我們可以通過繼承View 重寫 onSizeChanged方法得到View尺寸變化來判斷鍵盤是否彈起:

int minKeyboardHeight = dm.heightPixels / 4; (屏幕高度1/4)

當(dāng) oldh - h > minKeyboardHeight時(shí),鍵盤彈起

當(dāng) h - oldh > minKeyboardHeight時(shí),鍵盤隱藏

如此即可獲取鍵盤的彈起、隱藏狀態(tài) 和鍵盤高度 inputHeight(同時(shí)也是表情布局高度) 。

問題2:表情和鍵盤切換時(shí)候,防止Dialog抖動(dòng)

表情和鍵盤切換時(shí)候,由于DialogViewHeight 高度變化導(dǎo)致的Dialog高度重新計(jì)算高度而產(chǎn)生抖動(dòng);那么當(dāng)表情和鍵盤切換時(shí)DialogViewHeight 中間 DialogViewHeight 高度固定不變導(dǎo)致界面抖動(dòng)。

鍵盤——>表情:因?yàn)楫?dāng)鍵盤彈起時(shí)候,我們已經(jīng)知道鍵盤的高度,那么當(dāng)切換表情時(shí)候:(鍵盤高度==表情高度)

①、 鎖高度 DialogViewHeight = CommentView高度 + inputHeight(鍵盤高度)。鎖高重點(diǎn)在于設(shè)置 DialogView固定值,同時(shí)設(shè)置 layoutParams.weight = 0F

②、然后設(shè)置表情布局 VISIBLE 和 隱藏鍵盤

③、釋放鎖高。釋放鎖高重點(diǎn)在于設(shè)置 DialogViewHeight = LinearLayout.LayoutParams.MATCH_PARENT,同時(shí)設(shè)置  layoutParams.weight = 1.0F

代碼:

//①鎖高:
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) CommentView.getLayoutParams();
layoutParams.height = DialogView.getHeight();
layoutParams.weight = 0.0f;
llContentView.setLayoutParams(layoutParams);
?
//②表情布局顯示
EmotionView.setVisibility(View.VISIBLE)
//隱藏鍵盤
?
//③釋放高度
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) DialogView.getLayoutParams();
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 1.0f;
llContentView.setLayoutParams(layoutParams);

表情——>鍵盤:表情切換鍵盤其實(shí)跟鍵盤切換表情一樣,分三步

①、 鎖高度:鎖高度 DialogViewHeight = CommentView高度 + inputHeight(鍵盤高度)。鎖高重點(diǎn)在于設(shè)置 DialogView固定值,同時(shí)設(shè)置 layoutParams.weight = 0F

②、然后設(shè)置表情布局 GONE 和 彈起鍵盤

③、釋放鎖高。釋放鎖高重點(diǎn)在于設(shè)置 DialogViewHeight = LinearLayout.LayoutParams.MATCH_PARENT,同時(shí)設(shè)置  layoutParams.weight = 1.0F

//①鎖高:
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) CommentView.getLayoutParams();
layoutParams.height = DialogView.getHeight();
layoutParams.weight = 0.0f;
llContentView.setLayoutParams(layoutParams);
?
//②表情布局隱藏
EmotionView.setVisibility(View.GONE)
//顯示鍵盤
?
?
//③釋放高度
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) DialogView.getLayoutParams();
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 1.0f;
llContentView.setLayoutParams(layoutParams);

總結(jié):

1、onSizeChanged方法,重點(diǎn)在于獲取鍵盤的高度。方便后面表情布局高度設(shè)置。

2、表情切換主要在于對(duì)布局進(jìn)行鎖高和釋放高度,來實(shí)現(xiàn)表情、鍵盤切換時(shí)候,Dialog布局高度是沒有變化。

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

相關(guān)文章

最新評(píng)論

溆浦县| 杨浦区| 利川市| 阿克苏市| 武平县| 华容县| 息烽县| 延庆县| 山西省| 邢台县| 军事| 搜索| 开阳县| 广丰县| 宝坻区| 民乐县| 墨竹工卡县| 双牌县| 中卫市| 平邑县| 驻马店市| 海阳市| 马公市| 龙川县| 兴城市| 博白县| 车险| 泰安市| 昂仁县| 吉安市| 江口县| 宽城| 依兰县| 广东省| 嘉义县| 图片| 南宫市| 芜湖县| 乌兰县| 扎兰屯市| 亳州市|