Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

layout - Android Studio: N value split into relatively equal columns (Editable)

I am currently developing a project in android studio in which I have a value N (21 for example) and I have to create a view of tables equally divided into 5 or almost 5 rows. But let's say that they change the value to 26, the rows 23-25 should appear below the row number 22, and then row 26 should appear on a new column, but it currently appears below it. The proper amount of rows appears, but vertically, and they should be split horizontally. This is a snippet of my code:

                        LinearLayout layoutHorizontalPrincipal = (LinearLayout) rootView.findViewById(R.id.layoutHorizontal);
                        LinearLayout layoutVerticalPrincipal = (LinearLayout) rootView.findViewById(R.id.layoutVertical);
                        int numeroBulto = 0;

                        for (int i = 0; i < diferenciaBultos; i++) {
                            if (i == 0) {
                                numeroBulto = arrayViewsBultosVertical.size();
                            }
                            LinearLayout layoutVertical = null;
                            if (auxiliarBultos) {
                                layoutVertical = new LinearLayout(rootView.getContext());
                                layoutVertical.setOrientation(LinearLayout.VERTICAL);
                                auxiliarBultos = false;
                            } else {
                                layoutVertical = new LinearLayout(rootView.getContext());
                                layoutVertical.setOrientation(LinearLayout.VERTICAL);
                            }
                            if (arrayViewsBultosVertical.size() % 5 == 0) {
                                View viewTitulo = getLayoutInflater().inflate(R.layout.crear_titulos_peso_bulto,null,false);
                                View viewAux = getLayoutInflater().inflate(R.layout.agregar_peso_bulto,null,false);
                                layoutVertical.addView(viewTitulo);
                                layoutVertical.addView(viewAux);
                                EditText textNumeroBulto = (EditText) viewAux.findViewById(R.id.editTextNumeroBulto);
                                textNumeroBulto.setText(numeroBulto+1+"");
                                numeroBulto++;
                                arrayViewsBultosVertical.add(viewAux);
                            }
                            for (int j = i; j < diferenciaBultos; j++) {
                                if (arrayViewsBultosVertical.size() % 5 != 0 && arrayViewsBultosVertical.size() < totalBultosFinal) {
                                    View viewAux = getLayoutInflater().inflate(R.layout.agregar_peso_bulto,null,false);
                                    EditText textNumeroBulto = (EditText) viewAux.findViewById(R.id.editTextNumeroBulto);
                                    textNumeroBulto.setText(numeroBulto+1+"");
                                    numeroBulto++;
                                    layoutVertical.addView(viewAux);
                                    arrayViewsBultosVertical.add(viewAux);
                                } else if (arrayViewsBultosVertical.size() % 5 == 0) {
                                    break;
                                }
                            }
                            layoutVerticalPrincipal.addView(layoutVertical);

                        }

Please help. Basically, I have to do this: This is the result I have to achieve with N amount of Bultos. They can add more or remove some

Here is a screenshot of my XML: A screenshot of XML file

If I need to add more information or anything please let me know. I really ran out of ideas and can't figure out how to do this

question from:https://stackoverflow.com/questions/65933183/android-studio-n-value-split-into-relatively-equal-columns-editable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...