Как сделать горизонтальный scroll для editText?
Как сделать scroll как на видео. Есть такая разметка:
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:autofillHints=""
android:ellipsize="start"
android:ems="10"
android:gravity="center"
android:hint="@string/editText3"
android:inputType="numberDecimal"
android:maxLength="15"
android:singleLine="true"
android:textColor="@color/blue"
android:textSize="17sp"
android:textStyle="bold"
tools:targetApi="o" />
Ответы (1 шт):
Автор решения: Andrew
→ Ссылка
Есть несколько способов. Например можно поместить ваше поле для ввода в другой макет:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/edit_text">
<EditText
android:layout_width="120dp"
android:layout_height="21dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="6dp"
android:background="#00000000"
android:imeOptions="actionDone"
android:maxLength="20"
android:maxLines="1"
android:paddingLeft="2dp"
android:textColor="#FFFFFF"/>
</RelativeLayout>
Либо поместить Edittext в HorisontalScrollView и настроить его таким образом:
<HorizontalScrollView
android:id="@+id/rlEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="true" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:enabled="false"
android:focusable="false"
android:maxLines="1"
android:singleLine="true"
android:scrollHorizontally="true" />
</HorizontalScrollView>
Можно настроить только поле для ввода и не помещать его в другие контейнеры:
android:singleLine="true"
android:scrollHorizontally="true"
android:maxLines="1"
Так же можно настроить программно из класса активности:
EditText editText = (EditText) findViewById(R.id.some_edittext);
editText.setHorizontallyScrolling(true);
editText.setMovementMethod(new ScrollingMovementMethod());