Viepager2 width changes can cause bugs
lozn00 opened this issue · comments
FREE commented
My application designed viewPager2 to be half the width of the screen, and when I clicked the switch I would hide the other half, so viewapger2 would be all over the screen, but now there is a serious problem
Overlap, fragment slides in the wrong place, deviates from the middle, ,
Outer width changes cause fragmen in viewPager2 to display incorrectly, overlap, TAB TAB positions incorrectly,
FREE commented
ImageView ivExpand = getBinding().ivExpandView;
if (ivExpand != null) {
ivExpand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getBinding().left.getVisibility() == View.VISIBLE) {
getBinding().left.setVisibility(View.GONE);
ivExpand.setImageResource(R.drawable.ic_view_fold);
} else {
getBinding().left.setVisibility(View.VISIBLE);
ivExpand.setImageResource(R.drawable.ic_view_expand);
}
}
});
}
FREE commented
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:animateLayoutChanges="true"
android:layout_height="match_parent"
android:background="@color/shallowGray"
android:paddingTop="@dimen/margin_default_dp"
android:paddingLeft="@dimen/margin_default_dp"
android:paddingRight="@dimen/margin_default_dp"
android:orientation="horizontal"
app:layout_behavior=".ui.behavior.FixScrollingFooterBehavior1">
<androidx.cardview.widget.CardView
android:layout_marginBottom="@dimen/margin_default_dp"
android:id="@+id/left"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.4"
android:layout_width="0dp"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent" >
<LinearLayout
android:layout_marginTop="@dimen/margin_default_dp"
android:layout_marginBottom="@dimen/margin_default_dp"
android:layout_marginLeft="@dimen/margin_default_dp"
android:layout_marginRight="@dimen/margin_default_dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_order_no"
style="@style/textinput_layout_style_black_deep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:hint="@string/inspet_order_number"
android:textSize="50sp"
app:lock="@{lock}"
>
<com.sotrun.app.ui.ScanEditText
android:id="@+id/ev_woo"
style="@style/edit_text_style"
app:lock="@{lock}" />
</com.google.android.material.textfield.TextInputLayout>
<com.sotrun.app.ui.spinner.EditSpinner
android:id="@+id/spinner_inspect_single_line"
style="@style/edit_spinner_style"
android:layout_width="match_parent"
android:layout_weight="1"
app:spinner_hint="@string/inspect_single_line"
app:spinner_mode="dialog" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_Cargo_receipt_number"
style="@style/textinput_layout_style_black_deep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/Cargo_receipt_number"
app:lock="@{lock}">
<com.sotrun.app.ui.MyEditText
android:id="@+id/ev_Cargo_receipt_number"
style="@style/edit_text_style"
android:enabled="false"
app:lock="@{lock}"
/>
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_supplier_no"
style="@style/textinput_layout_style_black_deep"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/supplier_number"
app:lock="@{lock}">
<com.sotrun.app.ui.MyEditText
android:id="@+id/ev_supplier_no"
style="@style/edit_text_style"
android:enabled="false"
android:imeOptions="actionNext|flagNoExtractUi"
app:lock="@{lock}" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btn_more_vendorno"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="\?"
android:textColor="@color/white" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_supplier_name"
style="@style/textinput_layout_style_black_deep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/supplier_name"
app:lock="@{lock}">
<com.sotrun.app.ui.MyEditText
android:id="@+id/ev_supplier_name"
style="@style/edit_text_style"
android:enabled="false"
app:lock="@{lock}" />
</com.google.android.material.textfield.TextInputLayout>
<com.sotrun.app.ui.spinner.EditSpinner
android:id="@+id/goods_partno_spinner"
style="@style/edit_spinner_style"
android:layout_width="match_parent"
android:layout_marginLeft="2dp"
android:layout_weight="1"
app:spinner_hint="@string/goods_partno"
app:spinner_mode="dialog"
/>
<com.sotrun.app.ui.spinner.EditSpinner
android:id="@+id/goods_category_spinner"
style="@style/edit_spinner_style"
android:layout_width="match_parent"
android:layout_weight="1"
app:spinner_hint="@string/goods_category"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_commodity_specification"
style="@style/textinput_layout_style_black_deep"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:hint="@string/commodity_specification"
app:lock="@{lock}">
<com.sotrun.app.ui.MyEditText
android:id="@+id/ev_commodity_specificationl"
style="@style/edit_text_style"
app:lock="@{lock}" />
</com.google.android.material.textfield.TextInputLayout>
<com.sotrun.app.ui.spinner.EditSpinner
android:id="@+id/purchase_ordernumber_spinner"
style="@style/edit_spinner_style"
android:layout_width="0dp"
android:layout_weight="1"
app:spinner_hint="@string/purchase_ordernumber"
app:spinner_mode="dialog"
/>
<com.sotrun.app.ui.spinner.EditSpinner
android:id="@+id/inspect_status_spinner"
style="@style/edit_spinner_style"
android:layout_width="0dp"
android:layout_weight="1"
app:spinner_hint="@string/inspect_status" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_wrap_incoming_number"
style="@style/textinput_layout_style_black_deep"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:hint="@string/incoming_number"
app:lock="@{lock}">
<com.sotrun.app.ui.MyEditText
android:id="@+id/ev_incoming_number"
style="@style/edit_text_style"
android:inputType="number"
app:lock="@{lock}" />
</com.google.android.material.textfield.TextInputLayout>
<com.sotrun.app.ui.date.TimeView
android:id="@+id/timeview_submission_date"
style="@style/timeview_style"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
app:lock="@{lock}"
app:timeview_hint="@string/submission_date" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_weight="1"
android:id="@+id/right"
android:paddingRight="@dimen/margin_default_dp"
android:paddingBottom="@dimen/margin_default_dp"
android:paddingLeft="@dimen/margin_default_dp"
android:layout_width="0dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/left"
android:orientation="vertical"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginBottom="2dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.sotrun.app.module.quality.iqc.MyTabLayout
android:id="@+id/tab_layout"
app:tabPaddingEnd="5dp"
android:layout_width="0dp"
android:layout_gravity="center"
android:layout_weight="1"
app:tabPaddingStart="5dp"
app:tabMode="fixed"
style="@style/style_tablayoutquality" />
<ImageView
android:id="@+id/iv_expand_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="@dimen/margin_default_dp"
android:paddingLeft="@dimen/margin_default_dp"
android:src="@drawable/ic_view_expand" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>