Кнопка не растягивается на 2 строки

387
29 января 2017, 13:19

Не могу понять по какой причине кнопка с ID totalButton, не расширяется на 2 строки, хотя rowSpan="2" указан.

Буду благодарен если кто-то укажет на мою ошибку.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/memory_text_view"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:paddingTop="15dp"
            android:paddingRight="10dp"
            android:textAlignment="textEnd"
            tools:text="Memory Field"
            />
        <TextView
            android:id="@+id/operation_text_view"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:paddingTop="15dp"
            android:paddingRight="10dp"
            android:textAlignment="textEnd"
            tools:text="Operation Field"
            />
        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:columnCount="4"
            android:rowCount="5">
            <ImageButton
                android:layout_column="0"
                android:layout_row="0"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/sumButton"/>
            <ImageButton
                android:layout_column="1"
                android:layout_row="0"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/differenceButton"/>
            <ImageButton
                android:layout_column="2"
                android:layout_row="0"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/multiplicationButton"/>
            <ImageButton
                android:layout_column="3"
                android:layout_row="0"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/divisionButton"/>
            <ImageButton
                android:layout_column="0"
                android:layout_row="1"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button7"/>
            <ImageButton
                android:layout_column="1"
                android:layout_row="1"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button8"/>
            <ImageButton
                android:layout_column="2"
                android:layout_row="1"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button9"/>
            <ImageButton
                android:layout_column="3"
                android:layout_row="1"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/clearButton"/>
            <ImageButton
                android:layout_column="0"
                android:layout_row="2"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button4"/>
            <ImageButton
                android:layout_column="1"
                android:layout_row="2"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button5"/>
            <ImageButton
                android:layout_column="2"
                android:layout_row="2"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button6"/>
            <ImageButton
                android:layout_column="3"
                android:layout_row="2"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/notYetDefinied"/>
            <ImageButton
                android:layout_column="0"
                android:layout_row="3"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button1"/>
            <ImageButton
                android:layout_column="1"
                android:layout_row="3"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button2"/>
            <ImageButton
                android:layout_column="2"
                android:layout_row="3"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button3"/>
            <ImageButton
                android:layout_column="3"
                android:layout_row="3"
                android:layout_rowSpan="2"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/totalButton"/>
            <ImageButton
                android:layout_column="0"
                android:layout_row="4"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/button0"/>
            <ImageButton
                android:layout_column="1"
                android:layout_row="4"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/commaButton"/>
            <ImageButton
                android:layout_column="2"
                android:layout_row="4"
                android:src="@mipmap/ic_launcher"
                android:layout_width="102dp"
                android:id="@+id/reverseButton"/>
        </GridLayout>
    </LinearLayout>
</LinearLayout>
Answer 1

На самом деле для кнопки totalButton доступна площадь двух клеток (по вертикали), но чтобы растянуть эту кнопку по всей доступной площади, необходимо добавить этой кнопке атрибут:

android:layout_gravity="fill"

Чтобы растянуть кнопку по высоте, нужно добавить атрибут:

android:layout_gravity="fill_vertical"

В Вашем случае подойдет любой из этих атрибутов, но второй будет предпочтительнее.

READ ALSO
Проблема с подключением второй БД

Проблема с подключением второй БД

У меня была одна БД, потом пришлось создать еще одну для других целейПосле создания поменял DATEBASE_VERSION, но все ровно ошибка:

436
Вложенный оператор switch

Вложенный оператор switch

Объясните пожалуйста в чём ошибка

485
Часть переключателей MPC-HC не работает при создание процесса ProcessBuilder&#39;м

Часть переключателей MPC-HC не работает при создание процесса ProcessBuilder'м

Класс в котором формируется объект ProcessBuilder:

498
ViewPager и RecyclerView получить текущий list

ViewPager и RecyclerView получить текущий list

Есть ViewPager в котором RecyclerView формируется список, используется FragmentStatePagerAdapter который сразу формирует несколько фрагментовСитуация такая,...

410