2017-03-18 2 views
0

Ich bin ein Anfänger bei Android. Ich habe einige Probleme. Ich erstelle eine Liste mit Namen, Nachnamen und Telefonen wie Adressbuch, die enthalten und eine Umschalttaste, die die Höhe jeder Zelle erhöhen, die alle Informationen wie Name, Telefon usw. enthält ... Aber nichts passiert. Mein Code ist unten:Ändern Layout_Height von Linearlayout

Das ist mein fragmentlayout.xml

<ListView android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true"> 

</ListView> 

Das ist mein rowlayout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/lay" 
    android:layout_width="wrap_content" 
    android:layout_height="60dp" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/txtitem" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:padding="10dp" 
     android:textSize="10sp" 
     /> 

</LinearLayout> 

Und das i ist mein Haupt

package com.example.serepasf.my_app2; 

    import android.app.Activity; 
    import android.app.ListActivity; 
    import android.content.Context; 
    import android.support.v7.app.AppCompatActivity; 
    import android.os.Bundle; 
    import android.util.Log; 
    import android.widget.CompoundButton; 
    import android.widget.LinearLayout; 


    import android.support.v4.app.FragmentActivity; 
    import android.support.v4.app.FragmentTransaction; 
    import android.widget.ToggleButton; 

    public class MainActivity extends FragmentActivity { 

     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.fragmentlayout); 
      ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); 
      toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        if (isChecked) { 
         LinearLayout l = (LinearLayout) findViewById(R.id.lay); 
         l.setLayoutParams(new LinearLayout.LayoutParams(320,320)); 
         // The toggle is enabled 
        } else { 
         // The toggle is disabled 
        } 
       } 
      }); 
      LstFragment lstfragment=(LstFragment)getSupportFragmentManager().findFragmentByTag("lstfragment"); 
      if(lstfragment==null){ 
       lstfragment=new LstFragment(); 
       FragmentTransaction transact=getSupportFragmentManager().beginTransaction(); 
       transact.add(android.R.id.content,lstfragment,"lstfragment"); 
       transact.commit(); 

      } 
     } 

    } 

Deshalb möchte ich die Höhe und Breite von Linear Layout ändern, legen die in rowlayout.xml Dank ist

+0

'findViewById (R.id.lay);'? Das gibt es nicht mehr, nachdem du 'transact.add (android.R.id.content, lstfragment' ... hast. Warum brauchst du ein Fragment, wenn du nur die gesamte Aktivität damit ersetzt hast? –

+0

Hast du 'l versucht. invalidate() 'nachdem Sie die Layout-Parameter gesetzt haben? – Christine

+0

Ich habe auch die Klasse LstFragment, die mir helfen, eine CSV mit allen Informationen zu lesen, die ich brauche und es in die Zeilen meiner Liste zu parsen. –

Antwort

0

warum Sie android:layout_height="60dp" geschrieben haben, wenn Sie es basierend auf dem Inhalt erweitern wollen, als warum mach es nicht android:layout_height="wrap_content" aber dann wird das Layout nicht konsistent sein

+0

Irgendwo habe ich gelesen, dass wenn ich android gesetzt: layout_height =„wrap_content“next kippe ich die Höhe ändern .. aber zuerst habe ich es so, dass ein nichts scheint zu Ereignis –

Verwandte Themen