【问题标题】:edit text height increases while changing the orientation更改方向时编辑文本高度增加
【发布时间】:2012-08-13 11:31:19
【问题描述】:

在我的应用程序中,我将屏幕方向锁定为纵向。但是当用户点击编辑文本框时我正在更改它。在纵向模式下它工作正常。但在横向模式下编辑文本高度几乎是实际大小的两倍。下面给出的是我用于编辑文本的 xml。

<EditText
        android:id="@+id/mylist_AddNewFFtext"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="@drawable/mylist_stdcenterelement"
        android:imeOptions="actionSend|actionGo|actionDone"
        android:inputType="text|textCapWords"
        android:maxLength="1000"
        android:padding="5dp"
        android:textColor="@android:color/black"
        android:textSize="14sp"
        android:textStyle="bold"
        android:visibility="visible" />

我已删除 weight=1 属性。但它不起作用。我该如何解决这个问题?

【问题讨论】:

  • 将宽度和高度更改为“wrap_parent”,这意味着视图将足够大以包含其内容。
  • 那么在我开始输入之前编辑框的大小将是零仪式?
  • 不,它不会是零!试试这个。
  • 是的,尺寸不为零......但它不能解决我的问题:(

标签: android size android-edittext orientation-changes


【解决方案1】:
<EditText
    android:id="@+id/mylist_AddNewFFtext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:layout_weight="1"
    android:background="@drawable/mylist_stdcenterelement"
    android:imeOptions="actionSend|actionGo|actionDone"
    android:inputType="text|textCapWords"
    android:maxLength="1000"
    android:padding="5dp"
    android:textColor="@android:color/black"
    android:textSize="14sp"
    android:textStyle="bold"
    android:visibility="visible" />

将您的布局高度设置为 0dp 到 wrap_content 因为您试图将文本插入到 0dp 高度的编辑文本框中

【讨论】:

  • 这就是我赋予 weight 属性的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多