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

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

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

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

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

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

問題1:由于無法獲取鍵盤彈起狀態(tài),但是鍵盤彈起,View尺寸變化,同時被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)

當 oldh - h > minKeyboardHeight時,鍵盤彈起

當 h - oldh > minKeyboardHeight時,鍵盤隱藏

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

問題2:表情和鍵盤切換時候,防止Dialog抖動

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

鍵盤——>表情:因為當鍵盤彈起時候,我們已經(jīng)知道鍵盤的高度,那么當切換表情時候:(鍵盤高度==表情高度)

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

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

③、釋放鎖高。釋放鎖高重點在于設(shè)置 DialogViewHeight = LinearLayout.LayoutParams.MATCH_PARENT,同時設(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);

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

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

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

③、釋放鎖高。釋放鎖高重點在于設(shè)置 DialogViewHeight = LinearLayout.LayoutParams.MATCH_PARENT,同時設(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方法,重點在于獲取鍵盤的高度。方便后面表情布局高度設(shè)置。

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

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

相關(guān)文章

最新評論

鄂温| 舒兰市| 哈密市| 元朗区| 乐平市| 英吉沙县| 大名县| 衡东县| 陆丰市| 富平县| 达州市| 神农架林区| 汉源县| 瑞金市| 山东| 泸定县| 克东县| 巴林右旗| 赤峰市| 汉源县| 渭源县| 云安县| 焉耆| 昌吉市| 兰考县| 洛南县| 盘锦市| 象山县| 重庆市| 桃园市| 延吉市| 潜山县| 普定县| 长沙市| 寿阳县| 嘉兴市| 特克斯县| 邢台市| 资溪县| 鄱阳县| 绥阳县|