0
yanlış

olduğu sol (değil% 33 ve sırasıyla% 66, hem de ilki için değil% 50): Bu emülatör olur ScreenshotPercentageRelativeLayout marjı Benim düğmeleri çok fazla sol yoluna itti olsun

de. Şu anda bir OnePlus One'da test ediyorum.

<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>

Ben de Github bu projeyi tutmak:

İşte PercentageRelativeLayout parçasıdır. Sorunumu nasıl gideririm? Ben de daire şeklinde kontroller yapmaya çalışıyorum ama sanırım bu mümkün değil, bazen oval olacaklar.

cevap

0

coffeButton'un yatay olarak ortalanmasını istiyorsanız, kenar boşluğunu ayarlarken düğme genişliğini dikkate almalısınız. Düğmenin genişliği% 30 olduğundan, ortalamak için app:layout_marginLeftPercent'un 50% - 30%/2 = 35% olması gerekir. Üst kenar boşluğu için app:layout_marginTopPercent33% - 20%/2 = 23% şeklindedir.

Aynı şey düğmelerin geri kalanı için de geçerlidir.