繁体   English   中英

我如何给一个 editText 一个固定的宽度

[英]How do i give an editText a fixed width

我如何给我的 EditText-s 一个固定的宽度。 这是我的代码

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="4dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date:"
                android:layout_weight="0"
                android:textColor="#FFBBB3B9" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColor="#c91f1f"
                android:saveEnabled="true"
                android:id="@+id/e1b"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Time:"
                android:layout_weight="0"
                android:textColor="#FFBBB3B9" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColor="#c91f1f"
                android:id="@+id/e1c"
                android:saveEnabled="true"
                 />
        </LinearLayout>

我试过 android:maxLines 和 android:maxWidth 属性,但我没能解决这个问题。

谢谢。

在 .xml 文件中,您可以这样做:

<EditText ... android:layout_width="28dp" .../>

您的 LinearLayout 的 android:orientation 是水平的。 您可以将其更改为垂直。

android:orientation="vertical"

您可以使用代码固定编辑文本的宽度:

EditText dittext = (EditText)findViewById(R.id.sometextview);
edittext.setMaxWidth(edittext.getWidth());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM