TableLayout dynamisch Eigenschaften setzen

L

Luser_k

Neues Mitglied
2
Hi,

ich habe eine Tabelle dynamisch erstellt, habe aber festgestellt, das man die
Eigenschaften der enthaltenen Layouts / TableRows oder Views nicht so
setzen kann wie in der XML oder im Layout-Editor.

z.B.

Wie setze ich Eigenschaften wie zb.


  • Layout align parent right

  • Layout below

  • Layout gravity (also nicht normal gravity)

So wie ich das sehe, kann man dann keine anständige Formatierung der Views / Layouts machen!?!

Oder?

Bitte um Android-Hilfe :)
 
Also mein Ziel:

35 Zellen generieren, die RelativeLayouts, das wiederum 2 TableRows enthält.
Die TableRows enthalten wiederum Views (TextViews und ImageViews), die
entsprechend angeordnert werden müssen.

Also wenn mein Activity startet, dann erhalte ich einen schwarzen Bildschirm
im Emulator und später eine Fehlermeldung, das Android nicht mehr responded.

Hier ist mein code:

Code:
    public void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testcalendar);
        createCalendar();

        ...
   }
Code:
    public void createCalendar(){
        
        //Root tabelle
        TableLayout table = (TableLayout) findViewById(R.id.TableLayout02);
              
        //Zeilen
        TableRow tr = new TableRow(this);       
        
        //Erstelle 7 Zeilen
        for(int i=0;i<6;i++){
            
            tr.setGravity(Gravity.CENTER_HORIZONTAL);            
            tr.setId(100+i);                    
            tr.setLayoutParams(
                new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT
                )    
            );
            
            RelativeLayout rl = new RelativeLayout(this);
            
            //Erstelle 7 Zellen pro Zeile
            for(int k=0;k<7;i++){    
            
                Context context = getBaseContext();
                Resources res = context.getResources();
                Drawable d = res.getDrawable(R.drawable.background_nine_cell);
            
                //RELATIVE LAYOUT
                rl = new RelativeLayout(this);
                rl.setBackgroundDrawable(d);
                rl.setId(200+i);            
                rl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
            
                    //TABLE ROW
                    TableRow tr1 = new TableRow(this);
                    tr1.setId(300+i);
                    tr1.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                
                        //textview
                        TextView tv1 = new TextView(this);
                        tv1.setId(400+i);
                        tv1.setGravity(Gravity.CENTER_HORIZONTAL);
                        tv1.setText("0");
            
                        //imageview
                        ImageView iv1 = new ImageView(this);
                        iv1.setId(500+i);
                        iv1.setBackgroundResource(R.drawable.bueroklammen_klein);
                        
                    tr1.addView(tv1);
                    tr1.addView(iv1);
                        
                    //TABLE ROW
                    TableRow tr2 = new TableRow(this);
                    tr2.setId(600+i);
                    tr2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                    
                        //RELATIVE LAYOUT
                        RelativeLayout rl1 = new RelativeLayout(this);
                        rl1.setId(700+i);
                        rl1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                    
                            //imageview
                            ImageView iv2 = new ImageView(this);
                            iv2.setId(800+i);
                            iv2.setImageResource(R.drawable.roterpunkt_klein);
                            
                            //imageview
                            ImageView iv3 = new ImageView(this);
                            iv2.setId(900+i);
                            iv2.setImageResource(R.drawable.schmetterling_klein_schief);

                            //imageview
                            ImageView iv4 = new ImageView(this);
                            iv2.setId(1000+i);
                            iv2.setImageResource(R.drawable.schmetterling_klein_schief_transparenz);

                        rl1.addView(iv2);
                        rl1.addView(iv3);
                        rl1.addView(iv4);                                                
                        
                    tr2.addView(rl1);
                
                rl.addView(tr1);
                rl.addView(tr2);

            } // end of days in a week
            tr.addView(rl);
        }// end of weeks in a month
        
        table.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
 
    }
Hier das Layout (siehe fettgemarkerte TableLayout, da soll die Generierung hin)

Code:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/CalenderBackground" android:background="@drawable/background">

<RelativeLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/RelativeLayout00">
    <ImageView android:id="@+id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/balls" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"/>

<ScrollView android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scrollbars="vertical">        

    <LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent" android:gravity="center_horizontal">        

        <LinearLayout android:layout_height="wrap_content" android:background="@color/white" android:layout_width="fill_parent" android:gravity="center_horizontal" android:id="@+id/LinearLayout02">
            <ImageView android:id="@+id/ImageView01" android:layout_height="wrap_content" android:src="@drawable/logotop" android:background="@color/white" android:layout_gravity="center_horizontal" android:padding="2dp" android:layout_width="wrap_content"/>
        </LinearLayout>
        
        <TableLayout android:layout_height="fill_parent" android:stretchColumns="1" android:layout_width="fill_parent" android:layout_margin="4dip" android:id="@+id/TableLayout01">
            <TableRow android:gravity="center_horizontal" android:id="@+id/TableRow00">                                
                
                <TextView android:id="@+id/monatjahr" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_gravity="center_horizontal" android:gravity="center_horizontal" android:visibility="visible" android:textSize="25px"/>
                
            </TableRow>
        </TableLayout>            

        [B]<TableLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:stretchColumns="0,1,2,3,4,5,6" android:layout_margin="8dip" android:id="@+id/TableLayout02">  [/B]      

        </TableLayout>
    </LinearLayout>
</ScrollView>
</RelativeLayout>
</LinearLayout>
 
Du hast eine endlosschleife produziert
for(int k=0;k<7;i++)
 

Ähnliche Themen

A
Antworten
1
Aufrufe
637
swa00
swa00
M
  • maksimilian
Antworten
3
Aufrufe
1.125
maksimilian
M
L
Antworten
8
Aufrufe
1.310
jogimuc
J
Zurück
Oben Unten