0

Мои кнопки получить толкнул на левый путь слишком много (не 33% и 66% соответственно, а также не 50% для первого): ScreenshotPercentageRelativeLayout левое поле неверен

Это происходит в эмуляторе также. В настоящее время я тестирую это на OnePlus One.

Вот PercentageRelativeLayout часть:

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

Я также держать этот проект в Github. Как исправить мою проблему? Я также пытаюсь использовать круглые элементы управления, но я думаю, что это невозможно, иногда они будут овальными.

ответ

0

Если вы хотите, чтобы ось coffeButton была горизонтальной, вы должны учитывать ширину кнопки при настройке поля. Так как ширина кнопки составляет 30%, для центровки потребуется app:layout_marginLeftPercent быть 50% - 30%/2 = 35%.

Для верхнего края app:layout_marginTopPercent является 33% - 20%/2 = 23%.

То же самое относится и к остальным кнопкам.

Смежные вопросы