【问题标题】:how to shrink an android window to fit content如何缩小android窗口以适应内容
【发布时间】: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>

谢谢

【问题讨论】:

    标签: android resize window


    【解决方案1】:

    将所有 LinearLayouts 和 TextView 的宽度设置为 wrap_content。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-24
      • 1970-01-01
      • 2011-10-22
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      相关资源
      最近更新 更多