[英]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>
我在相對布局的下面使用GridLayout。 我想在此添加5列但未添加。 當我添加5列時,這表現得非常糟糕。 我想制作科學計算器我想使用網格布局來安排我的所有按鈕。
我想用5X7表來安排我的全部按鈕。 我嘗試了幾次,但我無法在代碼中添加第5列。
簡單地刪除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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.