[英]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.