Hello. Before launching the application, it looks like this: enter image description here

Like the height of the buttons are equal. But after starting the application, it looks like this: enter image description here

As you can see, the last element leaves the screen border or its height has decreased. As well as the height of the Button-s are no longer equal. Why is this happening? What needs to be done to prevent this from happening? Here is the xml code:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="Вопрос" android:gravity="center" android:layout_width="match_parent" android:layout_height="185dp" android:textColor="#fff" android:id="@+id/QuestionText" android:background="#000000" android:textSize="20dp" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000000" > <Button android:text="Предыдущий" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:textColor="#000" android:background="#fff" /> <Button android:text="Следующий" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:textColor="#000" android:background="#fff" android:id="@+id/nextButton" android:onClick="ShowNextQuestion" /> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:text="Ответ А" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="70dp" android:textColor="#000000" android:onClick="OptionButtonPressed" android:id="@+id/opta" android:background="#fff" /> <Button android:text="Ответ В" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="70dp" android:textColor="#000000" android:background="#fff" android:id="@+id/optb" android:onClick="OptionButtonPressed" /> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:text="Ответ С" android:background="#fff" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="70dp" android:onClick="OptionButtonPressed" android:id="@+id/optc" /> <Button android:text="Ответ D" android:background="#fff" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="70dp" android:textColor="#000000" android:onClick="OptionButtonPressed" android:id="@+id/optd" /> </LinearLayout> 

  • What are the buttons for two in separate containers? - pavlofff

1 answer 1

Use relative RelativeLayout markup. Thus, you can set the dynamic dimensions of all elements and place them - some at the bottom of the screen, others above them. Some at the top of the screen, some under them.

In your current case, the total space is not enough to accommodate all the given elements, since they have clear dimensions, for example

 70dp