[英]How to align right a TextView in RelativeLayout which layout_width is wrap_content and it's parent layout has wrap_content to
[英]How to detect width of TextView that has attribute wrap_content?
我有一个带有元素 TextView 的布局
<TextView android:textColor="#ffffff" android:text="18 августа"
android:id="@+id/program_day1" android:layout_gravity="center"
android:textSize="18sp" android:textStyle="bold"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1" android:gravity="center" />
如何在 onStart (或其他)事件中检测到它的实际大小(和边距)? 现在它显示“-2”值
尝试使用 myTextView.getPaint().measureText(myTextViewtext) 它没有返回视图的大小,而是返回文本的大小,希望它可以帮助你
视图在实际绘制在屏幕上之前不会获得高度或宽度。
尝试在onSizeChanged
function 中显示宽度。 检查是否会显示真实尺寸。 使用getwidth
。
除此之外,您可以使用TextView.getWidth()
和Textview.getHeight()
来获取 w/h 和LayoutParams lp = (LayoutParams) TextView.getLayoutParams();
获取保证金值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.