0

Meine Tasten auch nach links Weg geschoben bekommen viel (nicht mehr als 33% bzw. 66% sowie 50% für die ersten): ScreenshotPercentageRelativeLayout linker Rand ist falsch

Diese im Emulator geschieht auch. Ich teste das gerade auf einem OnePlus One.

Hier ist der PercentageRelativeLayout Teil:

<android.support.percent.PercentRelativeLayout 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_below="@+id/textView" 
 
     android:layout_above="@+id/contactText"> 
 

 
     <Button 
 
      app:layout_widthPercent="30%" 
 
      app:layout_heightPercent="20%" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:background="@drawable/round_button" 
 
      android:text="Σουβλακι" 
 
      android:textColor="#fff" 
 
      android:id="@+id/souvlakiButton" 
 
      app:layout_marginTopPercent="0%" 
 
      app:layout_marginLeftPercent="33%"/> 
 

 
     <Button 
 
      app:layout_widthPercent="30%" 
 
      app:layout_heightPercent="20%" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:background="@drawable/round_button" 
 
      android:text="Burger" 
 
      android:textColor="#fff" 
 
      android:id="@+id/burgerButton" 
 
      app:layout_marginTopPercent="66%" 
 
      app:layout_marginLeftPercent="33%"/> 
 

 
     <Button 
 
      app:layout_widthPercent="30%" 
 
      app:layout_heightPercent="20%" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:background="@drawable/round_button" 
 
      android:text="Pizza" 
 
      android:textColor="#fff" 
 
      android:id="@+id/pizzaButton" 
 
      app:layout_marginTopPercent="0%" 
 
      app:layout_marginLeftPercent="66%"/> 
 

 
     <Button 
 
      app:layout_widthPercent="30%" 
 
      app:layout_heightPercent="20%" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:background="@drawable/round_button" 
 
      android:text="Κρέπα" 
 
      android:textColor="#fff" 
 
      android:id="@+id/pancakeButton" 
 
      app:layout_marginTopPercent="66%" 
 
      app:layout_marginLeftPercent="66%"/> 
 

 
     <Button 
 
      app:layout_widthPercent="30%" 
 
      app:layout_heightPercent="20%" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:background="@drawable/round_button" 
 
      android:text="Καφές" 
 
      android:textColor="#fff" 
 
      android:id="@+id/coffeeButton" 
 
      app:layout_marginTopPercent="33%" 
 
      app:layout_marginLeftPercent="50%" /> 
 

 
     </android.support.percent.PercentRelativeLayout>

Ich halte dieses Projekt auch bei Github. Wie behebe ich mein Problem? Ich versuche auch, kreisförmige Steuerelemente zu verwenden, aber ich denke, das ist nicht möglich, manchmal werden sie oval sein.

Antwort

0

Wenn Sie möchten, dass die coffeButton horizontal zentriert ist, sollten Sie bei der Einstellung des Randes die Breite der Schaltfläche berücksichtigen. Da die Breite des Knopfes 30% beträgt, würde zum Zentrieren app:layout_marginLeftPercent50% - 30%/2 = 35% sein.

Für den oberen Rand app:layout_marginTopPercent ist 33% - 20%/2 = 23%.

Das gleiche gilt für die übrigen Schaltflächen.