android drawableleft 垂直居中,Android TextView前加图标垂直居中第一行(仿大众点评购买须知/提示语)...
如上图,需求在每条提示语句前加一个小圆点,我刚看到需求就想到用 android:drawableLeft 来作,可作完发现:当TextView内容为单行的时候是没有问题的,多行的时候,添加的这个drawableLeft就随着TextView高度而垂直居中了,变成下面的样子 java
看了下发现android:drawableLeft &android:drawableRight 是始终垂直居中于高度的 android
翻来翻去没有找到解决方法,就决定用简单粗暴的方法: 布局
布局: 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这些随喜爱设置
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);
经过mTipText.getLineHeight() 来得到TextView的行高,再设置行高的一半Margin就能获得下面的效果 code
(注:若是设置了Padding或者Margin,mTipText.getLineHeight()*0.5 这就不必定是行高的一半(0.5)了,慢慢调整,设置过Padding和Margin后,会大于0.5) xml
与50位技术专家面对面20年技术见证,附赠技术全景图总结
以上是生活随笔为你收集整理的android drawableleft 垂直居中,Android TextView前加图标垂直居中第一行(仿大众点评购买须知/提示语)...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android中按钮间隔,Android
- 下一篇: Android实现自动清空,androi