我有一个可观察到的可放大3种类型的布局
mEventActivityViewModel.getEventPhotos().observe(this, new Observer<List<EventPhotosDao.EventPhotos>>() {
@Override
public void onChanged(List<EventPhotosDao.EventPhotos> eventPhotos) {
int position = eventPhotos.size();
switch (position){
case 0:
initAddPhotosButton2();
break;
case 1:
inflateOnePhotoLayout();
break;
case 2:
inflateTwoPhotoLayout();
break;
default:
inflateThreePhotoLayout();
break;
}
});
我将如何在MVVM体系结构中对动态膨胀的布局进行数据绑定?我所有的逻辑都将包含在Activity类中吗?
private void inflateOnePhotoLayout() {
View eventOnePhotosLayout = (View) LayoutInflater.from(this)
.inflate(R.layout.fragevent_photolayout_onephoto, mPhotosLayout, false);
ImageView imageView = (ImageView) eventOnePhotosLayout.findViewById(R.id.fragevent_onephotolayout_image1);
Glide.with(this).load(mEventPhotos.get(0).getBody()).apply(RequestOptions.centerCropTransform()).into(imageView);
mPhotosLayout.addView(eventOnePhotosLayout);
View eventNumPhotos_1 = (View) LayoutInflater.from(this)
.inflate(R.layout.vh_fragevent_numberpictures, mPhotosLayout, false);
TextView tvNumberPhotos = (TextView) eventNumPhotos_1.findViewById(R.id.vh_fragevent_tv_numberpictures);
tvNumberPhotos.setText("1");
mPhotosLayout.addView(eventNumPhotos_1);
}