我不確定它只有「最後一行」,但我們有一個應用程序,它具有帶有fill_parent寬度的wrapper的高度的TextView。文本正在被Java代碼動態地放入。儘管佈局中有足夠的空間,文本的最後一行仍然沒有顯示出來。它的內部是一個相當深的視圖層次結構,所以我的猜測是在那裏的度量邏輯越來越混亂,但它非常令人沮喪。我們需要猜測文本中會有多少行,並相應地設置'android:lines'以使其正常工作。TextView填充動態切斷文本的最後一行
有人看過?在代碼中,請參見id'contentTextView'。如果我拿出'android:lines',最後一行文字消失。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/flag"
>
<include android:id="@+id/incHeader" layout="@layout/header"/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="101dp"
android:background="@drawable/headershadow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="101dp"
android:background="@drawable/footershadow"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gybcontentback"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<include android:id="@+id/gybHeaderInclude" layout="@layout/gybcontentheader"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#4f4f4f"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:lines="9"
android:id="@+id/contentTextView"/>
<ImageView
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_blue_rascal_button"
android:id="@+id/buttonMoreInfo"/>
</LinearLayout>
</FrameLayout>
<include android:id="@+id/incFooter" layout="@layout/menu"/>
</LinearLayout>
Java代碼。我在onCreate中使用標準Java字符串填充TextView。
@Override
protected String body()
{
return "Rascal Flatts and The Jason Foundation, Inc. are working together to prevent suicide.\n\n" +
"Your Battle Buddy (or family member) may need a friend.\n\n" +
"Take the pledge to B1.";
}
的基類調用,以獲得實際的文本
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(contentView());
wireMenu();
TextView headerText = (TextView) findViewById(R.id.gybHeaderText);
if(headerText != null)
headerText.setText(header());
((TextView) findViewById(R.id.contentTextView)).setText(body()); // This is where the text is set
}
無論如何,我煮了下去。我正在切割部件以查看剩下的部分,但仍然遇到同樣的問題。我想我可能已經找到觸發器和解決方案,但不是「原因」。
我們能否看到與該問題相關的Java代碼? –
凱文,看看你什麼時候調用setText()bc可能會影響wrap_content實際繪製的方式可能是有用的.. – LuxuryMode