![](/img/trans.png)
[英]TextView being cut off in Custom ArrayAdapter inside ListView
[英]TextView inside FrameLayout being cut-off and not wrapping
我有一个FrameLayout
,它动态添加TextViews
。 目前,边缘附近的TextViews不包装在父FrameLayout的末尾,并且正在离开屏幕。 FrameLayout使用wrap_content
作为宽度和高度:
<FrameLayout
android:layout_margin="10dp"
android:id="@+id/wrappingFrameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00ff00"
>
正在创建TextViews
,然后使用.setTranslationX()
和.setTranslationY()
将其转换为某个位置。
我尝试使用SO上其他地方找到的一些答案进行换行,例如在TextView上将LayoutParams设置为WRAP_CONTENT:
newTextView.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
我也试过newTextView.setSingleLine(false);
但那也没有用。
有任何想法吗?
编辑:所以我注意到动态添加的视图都没有响应它们上的任何方法,除了color / textsize之类的东西。 我尝试调用setMinLines(3)
和.setWidth(100)
,但它们没有效果。
您可以尝试使用FrameLayout.MarginLayoutParams
而不是.setTranslationX()
和.setTranslationY()
来定位TextViews
。
就像是:
FrameLayout.MarginLayoutParams layoutParams = (FrameLayout.MarginLayoutParams)textView.getLayoutParams();
layoutParams.leftMargin = xPosition;
layoutParams.topMargin = yPosition;
textView.setLayoutParams(layoutParams);
(我遇到了相反的问题TextViews
正在包装,但我希望它们被截断。我使用的是LayoutParams
和边距。更改为setTranslation
为我修复了它。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.