Я не могу добавить 5-й столбец в мой код - PullRequest
0 голосов
/ 20 марта 2019
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="100"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/reletive"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:text="Hello World!"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/output"
            android:gravity="end"
            android:text="Hello World!"
            android:textSize="30sp" />
    </RelativeLayout>

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/reletive"
        android:numColumns="5"
        tools:ignore="InvalidId">

        <Button
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:layout_column="4"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:text="1" />

        <Button
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:layout_column="4"
            android:layout_columnWeight="1"
            android:text="1" />
    </GridLayout>
</RelativeLayout>

Я использую GridLayout в нижней части Relative Layout. Я хочу добавить 5 колонок в это, но не добавлено. Когда я добавляю 5 столбец, это ведет себя очень плохо. Я хочу сделать научный калькулятор, и я хочу использовать макет сетки, чтобы расположить мою кнопку «все».

Я хочу использовать таблицу 5X7 для размещения кнопки «Все». Я пытаюсь несколько раз, но я не могу добавить 5-й столбец в моем коде.

1 Ответ

0 голосов
/ 20 марта 2019

Простое удаление android:layout_columnWeight="1" и android:layout_rowWeight="1" решит проблему.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:orientation="vertical"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_weight="100">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/reletive"  >
        <TextView
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="Hello World!"
            android:gravity="end" />
        <TextView
            android:id="@+id/input"
            android:layout_below="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="Hello World!"
            android:gravity="end"/>
    </RelativeLayout>
    <GridLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:ignore="InvalidId"
        android:layout_below="@+id/reletive"
        android:numColumns="5">

        <Button
            android:layout_row="0"
            android:layout_column="0"
            android:text="1"/>
        <Button
            android:layout_row="0"
            android:layout_column="1"
            android:text="1"/>
        <Button
            android:layout_row="0"
            android:layout_column="2"
            android:text="1"/>
        <Button
            android:layout_row="0"
            android:layout_column="3"
            android:text="1"/>
        <Button
            android:layout_row="0"
            android:layout_column="4"
            android:text="1"/>
        <Button
            android:layout_row="1"
            android:layout_column="0"
            android:text="1"/>
        <Button
            android:layout_row="1"
            android:layout_column="1"
            android:text="1"/>
        <Button
            android:layout_row="1"
            android:layout_column="2"
            android:text="1"/>
        <Button
            android:layout_row="1"
            android:layout_column="3"
            android:text="1"/>
        <Button
            android:layout_row="1"
            android:layout_column="4"
            android:text="1"/>
    </GridLayout>
</RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...