There are several (or rather quite a few) stages in the application. Each stage (separate activation) has a set of imageViews (at each stage - a different number). Dimensions (width, height), as well as indents from the container borders, each imageView receives from the array created in each activity:

 int[] viewsWidth={100,150,200,...} int[] viewsHeight={120,100,180, ...} int[] viewsLeftMargin ={20,150,30,80, ...} int[] viewsTopMargin ={180,250,50,120, ...} ImageView[] imageViews ={image1,image2,imge3,image4, ...} 

Further, these data in the createImageViews() method, which is in oncreate , are processed so that the pictures on different displays look correct ( ie, for a larger display, the size of the picture and indents increase, for a smaller one, decrease ).

Well, and so it happens at each stage (activit): 4 arrays are created + an ImageViews array, + a method that processes all this.

It begs the thought to simplify it all, but how? According to the MVC principle? I am not a very big specialist in java, I have little experience.

For example, you can put all the arrays (except for the array with pictures, of course) in the resource file, and the arrays will contain the parameters of all ImageView in the application, and not just one activation. Then create a model (Model1) that will bind 4 parameters {width, height, offset, indent}, then create a class that will create a List (paramsViewList) from Model1 objects, and then in each activate the created imageView array in the createImageViews() method to assign the appropriate values ​​from paramsViewList.

In general, I think correctly, and will this option be a complication ( in fact ), and not an improvement in the code, and are there any more interesting ideas?

  • Why not use the standard mechanisms of the system dimensions resources ? - eugeneek
  • @eugeneek I wrote about placing all the arrays in the resource file. It will be in any case correct, because properly store this kind of data in resources. - VolhaGomel
  • So you talked about these resources. Yes, that's right, that's what they came up with. And no models, sheets are needed. Just specify these parameters in the layout and that's it. - eugeneek
  • @eugeneek then there will be a lot of almost duplicate code in all activations. In the first activation, I will create 4 arrays with parameters (but using resources) + an ImageView array, in the second again 4 arrays, in the third again 4 arrays + an ImageView array. if you do not create arrays, and refer to the lines from the resources, then the code will be added ... That's what I'm writing. Somewhere (according to logic) there should be one place, one class that stores data for all ImageView of all activations, and in each specific activity they come from this class, but you will need to create your own imageView in each activity. - VolhaGomel

0