首页 > 系统 > Android > 正文

【完美解决系列】Android在自定义Dialog中TextView内容显示不全的问题

2019-11-09 15:40:12
字体:
来源:转载
供稿:网友

在自定义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”,不然的话也会影响布局。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表