Подтвердить что ты не робот

Android Layout выравнивает нижний

В моем приложении есть следующий макет:

  <?xml version="1.0" encoding="utf-8"?>
  <ScrollView  
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ScrollView01"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:scrollbars="vertical"
     android:background="@drawable/bbg">
     <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
           android:id="@+id/Title"
           android:text="@string/order_status"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal"
           android:textSize="26sp"
           android:textColor="#000000"
           android:shadowColor="#FFFFFF"
           android:shadowDx="0.5"
           android:shadowDy="0.5"
           android:shadowRadius="1.0"/>
           <LinearLayout
              android:orientation="vertical"
              android:id="@+id/MainStatusWindow"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_margin="10sp"
              android:background="@drawable/rounded_corners">
              <TextView
                 android:id="@+id/RateInfo"
                 android:text=""
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textSize="16sp"
                 android:layout_margin="10sp"
                 android:textColor="#5C5C5C"/>
              <ImageView
                 android:src="@drawable/line"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"/>
              <TextView
                 android:id="@+id/OrderStatus"
                 android:text="@string/please_wait"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center_horizontal"
                 android:textSize="20sp"
                 android:layout_margin="10sp"
                 android:textColor="#222222"/>
              <ImageView
                 android:src="@drawable/line"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"/>
              <TextView
                 android:id="@+id/TimerStatus"
                 android:text="0:00"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center_horizontal"
                 android:textSize="50sp"
                 android:layout_margin="10sp"
                 android:textColor="#222222"/>
           </LinearLayout>
           <Button android:id="@+id/Cancel"
              android:layout_marginTop="10sp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/cancel_order"
              android:textSize="18sp"
              android:textColor="#111111"
              android:layout_alignParentBottom="true"
              android:background="@drawable/button_red"/>
     </LinearLayout>
  </ScrollView>

Мне нужно, чтобы последняя кнопка была внизу страницы. Рисунок ниже показывает, что мне нужно (слева, что у меня есть, справа, что мне нужно).

Explanation

Спасибо.

4b9b3361

Ответ 1

Общая организация компоновки должна быть:

<LinearLayout orientation="vertical">
    <ScrollView android:layout_weight="1"
         android:width="fill_parent"
         android:height="wrap_content">
        ... linear layout with your TextViews ...
    </ScrollView>
    <Button/>
</LinearLayout>

Атрибут layout_weight="1" заставляет этот вид заполнять доступное пространство во внешнем LinearLayout и нажимает вашу кнопку на дно.

Изменить - если вы хотите, чтобы кнопки также прокручивались, вам следует следовать статье Романа Гая , используя fillViewPort и установив a layout_weight для одного из ваших детей LinearLayout.

Ответ 3

Вы можете использовать свой ScrollView и кнопку внутри RelativeLayout и установить Android: layout_alignParentBottom для кнопки.

Ответ 4

Это обычная проблема, но ее легко исправить:

1) Используйте параметр relativeLayout 2) Там есть два вида или макеты. Сначала выровняйте верхнюю часть и получите нижнее поле, равное высоте нижней. Второй выравнивается в нижней части

Готово! Надеюсь, это поможет.