Кнопки падают с экрана - PullRequest
       49

Кнопки падают с экрана

0 голосов
/ 25 октября 2011

Я пытаюсь создать меню на основе кнопок, используя относительное расположение. Я пытаюсь выложить их в сетке, используя

android:below=""
android:above=""
android:toLeftOf=""
android:toRightOf="" 

команда

Я попытался добавить еще одну кнопку ниже трех кнопок, которые у меня уже были, но вместо изменения размера кнопок, чтобы соответствовать родительскому элементу, четвертая кнопка вместо этого падает ниже края экрана. Есть ли способ обойти это, потому что я не хочу, чтобы на маленьких экранах отсутствовали кнопки. Вот мой макет

<RelativeLayout android:id="@+id/level1layout" 
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal">

 <Button android:id="@+id/OneLevel1Button"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_marginRight="10dp"
 android:layout_marginLeft="10dp"
 android:layout_marginBottom="10dp"
 android:layout_marginTop="10dp"
 android:text="1"
 android:textSize="25dp"
 android:background="@drawable/warpbutton"
 android:visibility="gone"/>

  <Button android:id="@+id/OneLevel2Button"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_marginRight="10dp"
 android:layout_marginLeft="10dp"
 android:layout_marginBottom="10dp"
 android:layout_marginTop="10dp"
 android:layout_below="@id/OneLevel1Button"
 android:text="2"
 android:textSize="25dp"
 android:background="@drawable/warpbutton"
 android:visibility="gone"/>

 <Button android:id="@+id/OneLevel3Button"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_marginRight="10dp"
 android:layout_marginLeft="10dp"
 android:layout_marginBottom="10dp"
 android:layout_marginTop="10dp"
 android:layout_below="@id/OneLevel2Button"
 android:text="3"
 android:textSize="25dp"
 android:background="@drawable/warpbutton"
 android:visibility="gone"/>

 <Button android:id="@+id/OneLevel4Button"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_marginRight="10dp"
 android:layout_marginLeft="10dp"
 android:layout_marginBottom="10dp"
 android:layout_marginTop="10dp"
 android:layout_below="@id/OneLevel3Button"
 android:text="4"
 android:textSize="25dp"
 android:background="@drawable/warpbutton"
 android:visibility="gone"/>

 </RelativeLayout>  

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

1 Ответ

1 голос
/ 25 октября 2011

Рассматривали ли вы использовать GridLayout?http://developer.android.com/reference/android/widget/GridLayout.html

По предложению OP очень полезный сайт, создающий пользовательский ButtonAdapter для GridView.

...