1

コードからレイアウトを作成しようとしたときに問題が発生しました。問題は、weightsum を使用して、水平方向と垂直方向にさまざまなレイアウトを作成していることです。アイデアは、画像 1 に似たディスプレイを作成することですが、現在は画像 2 を表示しています。

画像1

画像2

誰でも私を助けることができますか?さらに説明が必要な場合は、質問にお答えします。

Thx 4 すべて。

   for (NotificacionClase notifClase Indiv:lClases){

            LinearLayout linNuevo= new LinearLayout(this);
            linNuevo.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
            linNuevo.setWeightSum(2);
            linNuevo.setLayoutParams(LLParams);

            LinearLayout linNuevoCabecera= new LinearLayout(this);
            linNuevoCabecera.setOrientation(LinearLayout.HORIZONTAL);
            LinearLayout.LayoutParams llParamCabecera = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1);
            linNuevoCabecera.setWeightSum(2);
            linNuevoCabecera.setLayoutParams(llParamCabecera);
            TextView textFecha = new TextView(this);
            textFecha.setText(notifClaseIndiv.getFecha());
            textFecha.setLayoutParams( new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT,1.4f));


            TextView textTiempoTotal=new TextView(this);
            textTiempoTotal.setText(notifClaseIndiv.getTotal()+ " min.");
            textTiempoTotal.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,0.5f));
            textTiempoTotal.setTextSize(14);
            textFecha.setTextSize(20);
            linNuevoCabecera.addView(textFecha);
            linNuevoCabecera.addView(textTiempoTotal);

            final ImageView imagFlecha= new ImageView(this);
            imagFlecha.setBackgroundResource(R.drawable.flecha_bajo);
            imagFlecha.setLayoutParams( new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.1f));
            linNuevoCabecera.addView(imagFlecha);

            linNuevo.addView(linNuevoCabecera);
            for(NotificacionAsignaturas clase : notifClaseIndiv.getListClaseObj()){

                LinearLayout linNuevoClaseCabecera= new LinearLayout(this);
                linNuevoClaseCabecera.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1));
                linNuevoClaseCabecera.setOrientation(LinearLayout.VERTICAL);
                linNuevoClaseCabecera.setWeightSum(2);

                LinearLayout linNuevoClase= new LinearLayout(this);
               LinearLayout.LayoutParams linLayParamsNuevoClase=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1);
                linLayParamsNuevoClase.setMargins(30, 0, 0, 0);
                linNuevoClase.setLayoutParams( linLayParamsNuevoClase);
                linNuevoClase.setWeightSum(2);
                linNuevoClase.setOrientation(LinearLayout.HORIZONTAL);


                TextView txtClase = new TextView(this);
                txtClase.setText(clase.getClase());
                txtClase.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,1.4f));
                txtClase.setTextSize(18);

                TextView textTiempoClaseTotal=new TextView(this);
                textTiempoClaseTotal.setText(clase.getTotal()+ " min.");
                textTiempoClaseTotal.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,0.5f));
                textTiempoClaseTotal.setTextSize(14);

                linNuevoClase.addView(txtClase);
                linNuevoClase.addView(textTiempoClaseTotal);
                final ImageView imagFlechaClase= new ImageView(this);
                imagFlechaClase.setBackgroundResource(R.drawable.flecha_simple_bajo);
                imagFlechaClase.setLayoutParams( new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.1f));
                linNuevoClase.addView(imagFlechaClase);

                linNuevoClaseCabecera.addView(linNuevoClase);

                 LinearLayout linLayGroupTareas=new LinearLayout(this);
                LinearLayout.LayoutParams linLayParamsGroupTarea=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT,1);
                linLayGroupTareas.setLayoutParams(linLayParamsGroupTarea);
                for(NotificacionTareas tareaIndv: clase.getListTareas()){
                    LinearLayout linNuevaTarea=new LinearLayout(this);
                    LinearLayout.LayoutParams linLayParamsNuevaTarea=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    linLayParamsNuevaTarea.setMargins(45, 0, 0, 0);
                    linNuevaTarea.setLayoutParams( linLayParamsNuevaTarea);
                    linNuevaTarea.setWeightSum(3);
                    linNuevaTarea.setOrientation(LinearLayout.HORIZONTAL);


                    LinearLayout linGroupTarea=new LinearLayout(this);
                    linGroupTarea.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,2.3f));
                    linGroupTarea.setWeightSum(2);
                    linGroupTarea.setOrientation(LinearLayout.VERTICAL);


                    TextView txtAsign= new TextView(this);
                    txtAsign.setText(tareaIndv.getAsignatura());
                    txtAsign.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1f));

                    linGroupTarea.addView(txtAsign);
                    TextView txtDescrip= new TextView(this);
                    txtDescrip.setText(tareaIndv.getDescripcion().length()>20?tareaIndv.getDescripcion().substring(0,20)+"...":tareaIndv.getDescripcion());

                    LinearLayout.LayoutParams linLayParamsDescripcion=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1);
                    linLayParamsDescripcion.setMargins(15, 0, 0, 0);
                    txtDescrip.setLayoutParams(linLayParamsDescripcion);

                    linGroupTarea.addView(txtDescrip);

                    TextView txtTiempo= new TextView(this);
                    txtTiempo.setText(tareaIndv.getTiempo() + " min.");
                    txtTiempo.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,0.7f));

                    linNuevaTarea.addView(linGroupTarea);
                    linNuevaTarea.addView(txtTiempo);
                    linLayGroupTareas.addView(linNuevaTarea);



                }
                listTarea.add(linNuevoClaseCabecera);
                linNuevoClaseCabecera.addView(linLayGroupTareas);

                linNuevo.addView(linNuevoClaseCabecera);
                linNuevo.setClickable(true);
                listClasesTarea.add(linNuevo);
            }
            ((LinearLayout)findViewById(R.id.lnLayWindowNotification)).addView(linNuevo);
        }

より具体的には、問題は clase.getListaTareas() に複数の要素がある場合です。次に、ディスプレイに表示される一意の子は、最後に追加されたものです。問題はコードのこの部分にあると思いますが、わかりません...

 for(NotificacionTareas tareaIndv: clase.getListTareas()){
                    LinearLayout linNuevaTarea=new LinearLayout(this);
                    LinearLayout.LayoutParams linLayParamsNuevaTarea=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    linLayParamsNuevaTarea.setMargins(45, 0, 0, 0);
                    linNuevaTarea.setLayoutParams( linLayParamsNuevaTarea);
                    linNuevaTarea.setWeightSum(3);
                    linNuevaTarea.setOrientation(LinearLayout.HORIZONTAL);


                    LinearLayout linGroupTarea=new LinearLayout(this);
                    linGroupTarea.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,2.3f));
                    linGroupTarea.setWeightSum(2);
                    linGroupTarea.setOrientation(LinearLayout.VERTICAL);


                    TextView txtAsign= new TextView(this);
                    txtAsign.setText(tareaIndv.getAsignatura());
                    txtAsign.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1f));

                    linGroupTarea.addView(txtAsign);
                    TextView txtDescrip= new TextView(this);
                    txtDescrip.setText(tareaIndv.getDescripcion().length()>20?tareaIndv.getDescripcion().substring(0,20)+"...":tareaIndv.getDescripcion());

                    LinearLayout.LayoutParams linLayParamsDescripcion=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1);
                    linLayParamsDescripcion.setMargins(15, 0, 0, 0);
                    txtDescrip.setLayoutParams(linLayParamsDescripcion);

                    linGroupTarea.addView(txtDescrip);

                    TextView txtTiempo= new TextView(this);
                    txtTiempo.setText(tareaIndv.getTiempo() + " min.");
                    txtTiempo.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,0.7f));

                    linNuevaTarea.addView(linGroupTarea);
                    linNuevaTarea.addView(txtTiempo);
                    linLayGroupTareas.addView(linNuevaTarea);



                }
                listTarea.add(linNuevoClaseCabecera);
                linNuevoClaseCabecera.addView(linLayGroupTareas);

                linNuevo.addView(linNuevoClaseCabecera);
4

1 に答える 1