在自定义Dialog中使用了TextView,但是发现内容一直显示不全的问题,代码完全没有问题。经过测试后发现了解决方法,就是在自定义的Dialog中使用TextView组件时,设置Android:layout_width不能使用wrap_content,如:
<TextView
android:id="@+id/tv_dialog_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="tv_dialog_info"
android:textSize="15sp" />
应该改成match_parent,就可以解决此问题了。
代码如:
<TextView
android:id="@+id/tv_dialog_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="tv_dialog_info"
android:textSize="15sp" />
还需要注意的一点是,若你在自定义的Dialog布局中使用了Linearlayout,那么你必须在每个组件中都使用 android:layout_width=”match_parent”,不然的话也会影响布局。

本文介绍了解决自定义Dialog中TextView内容显示不全的问题。通过将TextView的layout_width属性从wrap_content改为match_parent,可以确保内容完整显示。此外,如果使用LinearLayout,则需为所有子视图设置相同的属性。
2208

被折叠的 条评论
为什么被折叠?



