简体   繁体   中英

I am not able to add 5th column in the my code

    <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>

I use GridLayout in the under of Relative Layout. I want to add 5 column in this But Not added. When I add 5 the column this is behave very bad. I want to make scientific Calculator And I want to use the Grid layout to arrange my all button.

I want to use 5X7 Table to arrange My all button. I try several times but I am not able to add 5th column in my code.

Simply removing the android:layout_columnWeight="1" and android:layout_rowWeight="1" will fix the problem.

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM