2016-04-11 12 views
0

This is what it shows on the emulatorTaste ändert das Layout beim Start Emulator

This is how it is on the Layout

Wann immer ich starten Sie den Emulator, um die Größe und die Positionierung der Tasten alle ändern .. Weiß jemand, warum dies geschieht? Ich bin ziemlich neu, also bin ich mir ziemlich sicher, dass ich hier ein paar Fehler mache. Würde etwas Hilfe lieben, lassen Sie mich wissen

Dies ist mein Code:

public class MainActivity extends Activity { 
    private static Button button_sbm; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     OnClickButtonListener(); 
    } 

     public void OnClickButtonListener() { 
      button_sbm = (Button)findViewById(R.id.button2); 
      button_sbm.setOnClickListener(
        new View.OnClickListener() { 
         @Override 
        public void onClick(View v) { 
         Uri uri = Uri.parse("http://google.com/"); 

         Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
         startActivity(intent); 
+0

Zuerst ist es wirklich eine schlechte Idee, die Knöpfe auf diese Weise zu platzieren. Versuchen Sie, 3 horizontale lineare Layouts zu verwenden und platzieren Sie Ihre Schaltflächen darin. Und bist du sicher, dass der Emulator der Telefonvorschau mit der XML entspricht? Und um die langen Strings in zwei Zeilen zu setzen, füge ein "\ n" im Android hinzu: text – Jey10

+0

Ich bin mir sicher, dass der Emulator das gleiche ist. Sollte ich das Relative Layout entfernen und durch 3 horizontale ersetzen? Oder einfach den Verwandten behalten und Horizontale hinzufügen? –

+0

Genau was antwortete megha jagdale – Jey10

Antwort

4
I have changed your layout plz refer this 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.rodekruis.MainActivity"> 


    <Button 
     android:id="@+id/button2" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button9" 
     android:layout_alignLeft="@+id/button10" 
     android:layout_marginBottom="20dp" 
     android:text="Nieuws" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button10" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/button8" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Afspraak maken" /> 


     <Button 
      android:id="@+id/button8" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Bezoek tijden" /> 

     <Button 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Contact" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button3" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Geef je mening!" /> 


     <Button 
      android:id="@+id/button4" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Route begeleiding" /> 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignLeft="@+id/button5" 
      android:layout_below="@+id/button8" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Specia-listen" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button5" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text="BWC" /> 


     <Button 
      android:id="@+id/button6" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text="Agenda" /> 


     <Button 
      android:id="@+id/button7" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Praktische 
informatie" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Vielen Dank, wirklich zu schätzen wissen! Das Layout ist fest und sieht gut aus. Das einzige, was sich geändert hat, ist, dass ich eine Aktivität auf dem "Nieuws" Button gemacht habe. Als ich darauf geklickt habe, wurde ich auf eine Webseite verwiesen. Jetzt funktioniert das nicht mehr, während der Name des Buttons sich nie geändert hat. –

+0

Ich fand heraus, dass es Taste 7 als Taste 2 und Taste 7 und Taste 6 sieht. Wenn ich eine Aktivität auf Taste 2 benutze und einen Link dazu verwende, starte ich den Emulator, und wenn ich auf Taste 2 klicke, habe ich gewonnen. t funktionieren, aber wenn ich auf Taste 7 klicke, funktioniert es. Sie haben gewechselt oder so, weißt du warum? –

+0

hinzufügen Schaltfläche Attribut "android: clickable =" true " –

0

Antwort auf die Frage nach dem Onclick:

Sie ein Onclick-Attribut, um Ihre Schaltflächen setzen sollte:

<Button 
     android:id="@+id/button2" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button9" 
     android:layout_alignLeft="@+id/button10" 
     android:layout_marginBottom="20dp" 
     android:onclick="button2click" 
     android:text="Nieuws" /> 

und tun, wie dies in Ihrem Java:

public class MainActivity extends Activity { 
    private static Button button_sbm; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


    } 

    public void button2click (View v) 
     { 
      Uri uri = Uri.parse("http://google.com/"); 

      Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
      startActivity(intent); 
     } 
} 
Verwandte Themen