【发布时间】:2014-12-17 11:04:31
【问题描述】:
我有一个包含简单 TextView 的弹出窗口。如果我用更长的消息更新消息,则窗口会自动扩展以适应文本,但如果消息更短,它会保持相同的大小。如何重新触发窗口上的“调整大小”?
updateText 方法:
public void updateText(String message) {
TextView text = (TextView)view.findViewWithTag("text");
text.setText(message);
text.setGravity(Gravity.CENTER_HORIZONTAL);
popupWindow.showAtLocation(view, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 100);
}
窗口定义:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/shape1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical" >
<TextView
android:tag="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Now is the time for all good men to come to the aid of the party" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
谢谢
【问题讨论】: