기본값보다 EditText를 작게 만드는 방법은 무엇입니까?
-
19-08-2019 - |
문제
화면에 많은 수의 EditText 컨트롤을 표시해야하며 각각 0-2 자리 만 입력 할 수 있습니다. 기본 edittext 크기가 너무 넓어서 화면에 충분한 EditText 컨트롤이 표시되지만 더 좁게 만드는 방법을 알 수 없었습니다. 다음 속성을 시도했습니다
XML :
android:maxLength="2"
android:layout_width="20dip"
android:maxWidth="20px"
android:ems="2"
android:maxEms="2"
따라서 문제는 다음과 같습니다. EditText는 어떻게 기본값보다 작게 만들 수 있습니까?
해결책
대신이 방법을 시도하고 차이를 보여줍니다. 지정된 너비와 함께 layout_width를 사용하십시오.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:width="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:layout_width="40dip"
android:layout_height="wrap_content"
android:text="@string/hello"
android:maxLength="2"
/>
</LinearLayout>
다른 팁
이걸 시도하면 작동 할 수 있습니다 ....... Android : TextAppearance = "? Android : AttpeparancesMall"
이 페이지에서 Java 코드에서 동일하게 달성하는 방법을 검색하는 경우 ..
txtSample.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
테이블에있을 때, 당신이 설명 하듯이, Android : layout_gravity = "left"
제휴하지 않습니다 StackOverflow