Android Gridlayout-在延伸过去的图元上调整图元大小 简介/问题
在开始编程之前,我正在使用一个名为AIDE的移动应用程序(它是程序应用程序UI设计器)为我正在制作的移动应用程序创建布局。布局近乎完美。我希望播放器的两部分都在屏幕的顶部,倒置,以便两个玩家都能使用。然后我会在中间添加一个分配器,PrimeOne部分将在底部,中间的空白/分隔符。问题是,当分隔符设置为按高度换行内容时,它会向下过度延伸屏幕,将playerOne部分推离屏幕 我需要什么 我需要分隔器在高度上不断扩展,直到playerOne部分位于屏幕底部,playerTwo部分位于顶部 我试过的Android Gridlayout-在延伸过去的图元上调整图元大小 简介/问题,android,xml,grid-layout,android-gridlayout,Android,Xml,Grid Layout,Android Gridlayout,在开始编程之前,我正在使用一个名为AIDE的移动应用程序(它是程序应用程序UI设计器)为我正在制作的移动应用程序创建布局。布局近乎完美。我希望播放器的两部分都在屏幕的顶部,倒置,以便两个玩家都能使用。然后我会在中间添加一个分配器,PrimeOne部分将在底部,中间的空白/分隔符。问题是,当分隔符设置为按高度换行内容时,它会向下过度延伸屏幕,将playerOne部分推离屏幕 我需要什么 我需要分隔器在高度上不断扩展,直到playerOne部分位于屏幕底部,playerTwo部分位于顶部 我试过的
- 更改每个元素的行和列跨度
- 将各种图元上的布局重心更改为居中、填充、垂直填充等
- 修改分隔符的行和列
- 修改分隔符的重力、边距和填充
- 更改高度以匹配父对象 截图
10dp
)
带换行内容的布局
XML
基本上,我认为
GridLayout
对于您的父布局是错误的选择。您可以通过查看布局来判断它不是真正的网格。当然,您可以使用跨距使其适合您,但您最好选择一个不必抗争的父布局
我推荐ConstraintLayout
。它几乎是为这种布局量身定做的。你可以告诉它一些很好的事情,比如“把这个视图放在右上角”和“把另一个视图放在左下角”。或者“拉伸此视图以填充这两个其他视图之间的所有空间”
如果您将布局重新编写为使用ConstraintLayout
,则布局将是这样的:
基本上,我认为
GridLayout
对于您的父布局是错误的选择。您可以通过查看布局来判断它不是真正的网格。当然,您可以使用跨距使其适合您,但您最好选择一个不必抗争的父布局
我推荐ConstraintLayout
。它几乎是为这种布局量身定做的。你可以告诉它一些很好的事情,比如“把这个视图放在右上角”和“把另一个视图放在左下角”。或者“拉伸此视图以填充这两个其他视图之间的所有空间”
如果您将布局重新编写为使用ConstraintLayout
,则布局将是这样的:
它在我的手机助手上抛出错误,说“aapt:在包“thegaminghideout.yugioh”中的属性“layout\u constraintTop\u toTopOf”找不到资源标识符。这是因为我的手机助手可能不支持它吗?版面本身只输出文本“android.support.constraint.ConstraintLayout”。我明白了。AIDE(我正在使用的应用程序)默认情况下没有导入Maven库,所以我不得不手动将其添加到构建文件中,现在所有这些错误都消失了。谢谢!当我在手机上使用AIDE的App UI Designer程序时,现在它只显示文本android.support.constraint.ConstraintLayout
。AIDE安装了Maven库,因此布局正确如您所示。我将编辑我的问题,以获得其外观的屏幕截图;我只是想知道是否有可能使其正确显示,或者应用程序本身不支持它?它会在我的移动助手上抛出错误,并说“aapt:在“thegaminghideout.yugioh”包中找不到属性“layout_constraintTop_toTopOf”的资源标识符。这是因为我的移动助手可能不支持它吗?布局本身只输出文本“android.support.constraint.ConstraintLayout”,我找到了。助手(我正在使用的应用程序)默认情况下没有导入Maven库,所以我不得不手动将其添加到构建文件中,现在所有这些错误都消失了。谢谢!当我在手机上使用AIDE的App UI Designer程序时,现在它只显示文本android.support.constraint.ConstraintLayout
。AIDE安装了Maven库,因此布局正确如您所示。我将编辑我的问题,以获得其外观的屏幕截图;我只是想知道是否有可能将其正确显示,还是应用程序本身不支持它?
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
columnCount="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
rowCount="1"
android:columnCount="3"
android:layout_gravity="right"
android:orientation="horizontal"
android:rowCount="8">
<!-- Start of Player Two Section -->
<!-- Current LP -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="8000 LP"
android:minWidth="100dp"
android:gravity="center"
android:rotation="180"
android:id="@+id/playerTwo_LP"
android:layout_column="1"
android:layout_row="0"
android:layout_rowSpan="2"
android:layout_gravity="fill"/>
<!-- Toolkit -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="TOOLS"
android:rotation="180"
android:id="@+id/playerTwo_toolKit"
android:layout_row="1"
android:layout_column="0"/>
<!-- Cards Tool -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="CARDS"
android:layout_row="1"
android:layout_column="2"
android:rotation="180"
android:id="@+id/playerTwo_CardLibrary"/>
<!-- Add LP -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ADD LP"
android:layout_gravity="fill"
android:rotation="180"
android:id="@+id/playerTwo_addLP"
android:layout_row="0"
android:layout_column="0"/>
<!-- Lose LP -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="LOSE LP"
android:layout_column="2"
android:rotation="180"
android:id="@+id/playerTwo_loseLP"
android:layout_row="0"/>
<!-- Player Two Name -->
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:layout_row="2"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:text="Seto Kaiba"
android:gravity="center"
android:id="@+id/playerTwo_name"
android:textStyle="italic"
android:rotation="180"/>
<!-- End of Player Two Section -->
<View
android:background="?android:attr/dividerVertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_row="3"
android:layout_rowSpan="1"
android:layout_gravity="center|fill"/>
<!-- Start of Player One Section -->
<!-- Player One Name -->
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:layout_row="5"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:text="Yugi Muto"
android:gravity="center"
android:id="@+id/playerOne_name"
android:textStyle="italic"
android:rotation="0"/>
<!-- Current LP -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="8000 LP"
android:minWidth="100dp"
android:gravity="center"
android:rotation="0"
android:id="@+id/playerOne_LP"
android:layout_column="1"
android:layout_row="6"
android:layout_rowSpan="2"
android:layout_gravity="fill"/>
<!-- Toolkit -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="TOOLS"
android:rotation="0"
android:id="@+id/playerOne_toolKit"
android:layout_row="6"
android:layout_column="0"
android:layout_gravity="center"/>
<!-- Cards Tool -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="CARDS"
android:layout_row="6"
android:layout_column="2"
android:rotation="0"
android:id="@+id/playerOne_CardLibrary"/>
<!-- Add LP -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ADD LP"
android:layout_gravity="fill"
android:id="@+id/playerOne_addLP"
android:layout_row="7"
android:layout_column="0"/>
<!-- Lose LP -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="LOSE LP"
android:layout_column="2"
android:id="@+id/playerOne_loseLP"
android:layout_row="7"/>
<!-- End of Player One Section -->
</GridLayout>