У меня есть 3 HorizontalScrollview
, для каждого из них у меня есть customView
, содержащие editText
, которые я добавляю динамически в зависимости от ответа веб-службы. Проблема в том, что когда я хочу изменить значение в editText
и появляется клавиатура, HorizontalScrollView
автоматически прокручивается до конца, поэтому я не могу правильно ввести значение в текст редактирования. Мой вопрос: как предотвратить автопрокрутку в моем HorizontalScrollView
, чтобы я мог вводить значение в моем editText
? и HorizontalScrollView
прокручивается только тогда, когда пользователь прокручивает его.
У меня есть поиск, и моя проблема похожа на эту тему, но предложение не работал. вот обходной путь, который я уже пробовал:
- Добавьте
android:windowSoftInputMode="stateHidden|adjustNothing"
илиandroid:windowSoftInputMode="stateHidden|adjustResize"
, уже попробуйтеadjustPan
и другую комбинацию, но это ни на что не влияет. Добавьте
android:descendantFocusability="beforeDescendants" android:focusable="true" android:focusableInTouchMode="true"
вLinearLayout
внутри моегоHorizontalScrollView
, и это также ничего не повлияет.Добавьте
android:descendantFocusability="blocksDescendants
,HorizontalScrollView
не прокручивается автоматически, но я не могу изменить значение в моем тексте редактирования, это похоже на то, когда я добавляюandroid:focusable = "false"
в свойeditText
Добавьте код ниже, но ничего не повлияйте.
scrollLayout.descendantFocusability = ViewGroup.FOCUS_BEFORE_DESCENDANTS scrollLayout.isFocusable = true scrollLayout.isFocusableInTouchMode = true scrollLayout.setOnTouchListener { v, event -> v.requestFocusFromTouch() false}
Вот мой код
private fun setUpList(rootLayout: LinearLayout, scrollLayout: HorizontalScrollView, items: List<ProductItem>) {
//config horizontal scroll view
scrollLayout.descendantFocusability = ViewGroup.FOCUS_BEFORE_DESCENDANTS
scrollLayout.isFocusable = true
scrollLayout.isFocusableInTouchMode = true
scrollLayout.setOnTouchListener { v, event ->
v.requestFocusFromTouch()
false
}
// add customView to linear layout
rootLayout.removeAllViews()
for (item in items) {
val view = EditableThumbnailProduct(context)
view.setProductInfo(item)
view.setOnProductChangeListener(onChangeListener())
rootLayout.setBackgroundColor(Color.TRANSPARENT)
rootLayout.addView(view)
}
}
Вот мой XML
<HorizontalScrollView
android:id="@+id/scrollMed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="@+id/contentMed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@android:color/transparent"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal" />
</HorizontalScrollView>
Вот мой пользовательский вид
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@android:color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<ImageView
android:id="@+id/img_thumbnail"
android:layout_width="150dp"
android:layout_height="120dp"
android:background="@color/gray_border"
android:scaleType="fitXY" />
<TextView
android:id="@+id/txt_product_name"
style="@style/DefaultTextTitle"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="5dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:text="@string/product_name_label" />
<TextView
android:id="@+id/txt_product_stock"
style="@style/DefaultTextSubTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center"
android:text="@string/available_stock_label" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_border" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<Button
android:id="@+id/btn_add_to_cart"
style="@style/WhiteTitle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:background="@drawable/round_button_orange"
android:gravity="center"
android:text="@string/buy_button_label"
android:visibility="invisible" />
<RelativeLayout
android:id="@+id/layout_plus_minus"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/btn_minus"
style="@style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="@drawable/round_button_blue"
android:paddingLeft="5dp"
android:paddingTop="11dp"
android:paddingRight="5dp"
android:paddingBottom="11dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_minus" />
<ImageView
android:id="@+id/btn_delete"
style="@style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="@drawable/round_button_blue"
android:padding="3dp"
android:scaleType="fitXY"
android:visibility="invisible"
app:srcCompat="@drawable/ic_delete" />
<EditText
android:id="@+id/txt_cart_amount"
style="@style/LightTextTitle"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:backgroundTint="@color/blue_text_color"
android:inputType="number"
android:maxLength="3"
android:paddingBottom="5dp" />
<ImageView
android:id="@+id/btn_plus"
style="@style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:background="@drawable/round_button_blue"
android:gravity="center"
android:padding="5dp"
android:scaleType="fitXY"
android:textSize="16sp"
app:srcCompat="@drawable/ic_plus" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
All sugestion will be appreciate. Thanks in advance.