I have a custom btn view that was reused many times,but
‘mBinding = CustomBtnGrayBinding.inflate(LayoutInflater.from(context), this);’
inflate too many times, make the parent view load too slow.
So, I wanna ask how can I make the inflate be less??
Every time I use CustomBtnGray it will inflate one time, too many I/O leads to slow load.
public class CustomBtnGray extends SkinConstraintLayout {
public CustomBtnGrayBinding mBinding;
public CustomBtnGray(Context context) {
this(context, null);
}
.....
private void initView(Context context) {
mBinding = CustomBtnGrayBinding.inflate(LayoutInflater.from(context), this);
textView = mBinding.stvText;
skinImageView = mBinding.clCityChoose;
}
private void initCustomAttr(Context context, AttributeSet attrs) {
....
}
}
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:designHeight="600"
app:designWidth="1024"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<com.dhmi.custom.CustomBtnGray
android:id="@+id/cbg_keyboard_1"
android:layout_width="@dimen/auto_dimen2_48"
android:layout_height="@dimen/auto_dimen2_48"
app:custom_btn_gray_text="1" />
<com.dhmi.custom.CustomBtnGray
android:id="@+id/cbg_keyboard_2"
android:layout_width="@dimen/auto_dimen2_48"
android:layout_height="@dimen/auto_dimen2_48"
android:layout_marginStart="@dimen/auto_dimen2_12"
app:custom_btn_gray_text="2"
app:layout_constraintBottom_toBottomOf="@+id/cbg_keyboard_1"
app:layout_constraintStart_toEndOf="@+id/cbg_keyboard_1"
app:layout_constraintTop_toTopOf="@+id/cbg_keyboard_1" />
....
</merge>
I know asynchronous loading and lazy loading mechanisms allow the parent view to be rendered first, making the page appear less cluttered. However, I believe that multiple inflates can be avoided.
**
I wanna reuse custom views to reduce code volume while avoiding I/O performance consumption caused by multiple inflates.Is this possible????**
frisky XP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.