![](/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.