android drawableleft 垂直居中,Android TextView前加图标垂直居中第一行(仿大众点评购买须知/提示语)...
如上圖,需求在每條提示語(yǔ)句前加一個(gè)小圓點(diǎn),我剛看到需求就想到用?android:drawableLeft 來作,可作完發(fā)現(xiàn):當(dāng)TextView內(nèi)容為單行的時(shí)候是沒有問題的,多行的時(shí)候,添加的這個(gè)drawableLeft就隨著TextView高度而垂直居中了,變成下面的樣子 java
看了下發(fā)現(xiàn)android:drawableLeft &android:drawableRight 是始終垂直居中于高度的 android
翻來翻去沒有找到解決方法,就決定用簡(jiǎn)單粗暴的方法: 布局
布局: spa
android:id="@+id/act_item_experience_datail_tip_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:orientation="horizontal">
android:id="@+id/tip_img"
android:layout_width="wrap_content"
android:src="@mipmap/tip_left"
android:layout_height="match_parent"/>
android:id="@+id/tip_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/gold"/>
margin、lineSpacingExtra這些隨喜愛設(shè)置
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, (int)(mTipText.getLineHeight()*0.5), 0, 0);
mTipImageView.setLayoutParams(lp);
經(jīng)過mTipText.getLineHeight() 來得到TextView的行高,再設(shè)置行高的一半Margin就能獲得下面的效果 code
(注:若是設(shè)置了Padding或者M(jìn)argin,mTipText.getLineHeight()*0.5 這就不必定是行高的一半(0.5)了,慢慢調(diào)整,設(shè)置過Padding和Margin后,會(huì)大于0.5) xml
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的android drawableleft 垂直居中,Android TextView前加图标垂直居中第一行(仿大众点评购买须知/提示语)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android中按钮间隔,Android
- 下一篇: Android实现自动清空,androi