android - EditText高度根据文字大小变化

标签 android xml layout android-edittext text-size

如果我改变 edittext 中的 textsize,edittext 的高度也会相应改变。我希望 edittext 的大小相同,并且我希望其中包含更小的提示或文本。我应该怎么办?以下是代码,我还发布了此布局的屏幕截图:

  <RelativeLayout
            android:id="@+id/normal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#4594e4"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/set"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_marginTop="05dp"
                android:padding="5dp"
                android:src="@drawable/bari" />

            <EditText
                android:id="@+id/etOrigin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/_35sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:layout_toEndOf="@+id/set"
                android:layout_toRightOf="@+id/set"
                android:background="#5fa7f1"
                android:inputType="textPersonName"
                android:text="My Location"
                android:textColor="#434343"
                android:textIsSelectable="true" />

            <EditText
                android:id="@+id/etDestination"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/etOrigin"
                android:layout_marginRight="@dimen/_35sdp"
                android:layout_marginTop="@dimen/_5sdp"
                android:layout_toEndOf="@+id/set"
                android:layout_toRightOf="@+id/set"
                android:background="#5fa7f1"
                android:inputType="textPersonName"
                android:onClick="wow"
                android:text="Where to go ?"
                android:textColor="#fff"
                android:textColorHint="#fff" />

            <ImageView
                android:id="@+id/swipe"
                android:layout_width="30dp"
                android:layout_height="27dp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="@dimen/_5sdp"
                android:background="@drawable/flip" />

        </RelativeLayout>

更改前的布局截图:

Screenshot of the layout before changing

更改文本大小后的布局截图:

Screenshot of layout after changing textsize

最佳答案

尝试使用 android:minHeightandroid:maxHeight 属性:

                            <EditText
                            android:id="@+id/etUserName"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="@string/hint_username"
                            android:imeOptions="actionNext"
                            android:inputType="textPersonName"
                            android:maxLines="1"
                            android:gravity="center_vertical"
                            android:minHeight="?actionBarSize"
                            android:maxHeight="?actionBarSize"
                            android:textColor="@color/textPrimary"
                            android:textSize="12sp"/>

                            <EditText
                            android:id="@+id/etUserEmail"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="@string/hint_username"
                            android:imeOptions="actionNext"
                            android:inputType="textEmailAddress"
                            android:maxLines="1"
                            android:gravity="center_vertical"
                            android:minHeight="?actionBarSize"
                            android:maxHeight="?actionBarSize"
                            android:textColor="@color/textPrimary"
                            android:textSize="14sp"/>

关于android - EditText高度根据文字大小变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48921786/

相关文章:

java - 读取带有 unicode 字符的原始文件

java - Java 的最佳配置文件

php - 如何在 PHP 上对 SimpleXMLElement 进行排序

android - 如何按中心对齐按钮并进行偏移

c# - 对应C# Control.SuspendLayout/ResumeLayout的swing方法

html - 如何在没有 javascript 的情况下使用 css 混合固定和百分比高度/宽度

android - 如何在运行时计算屏幕高度和宽度?

java - 如何禁用布局对齐?

getResources().getString(R.string.value) 中的 java.lang.NullPointer 异常;

xml - 使用 XSLT 显示时间表