我正在学习Android开发,并且正在尝试制作一个简单的计算器。我在计算器布局方面遇到一些问题。我认为,发布整个xml代码太笨拙了,因此我将发布我认为很重要的代码片段。
我将垂直LinearLayout作为最顶层的父级,然后有2个子级,一个水平LinearLayout(由显示您的输入的TextView和一个用来计算的按钮组成)和一个GridLayout,其值为0-9按钮和操作符。
问题是,网格布局将是带有按钮的4x4网格,当我要设置按钮的第一行时,每个按钮都需要获取layout_height,不能将其保留为空,如果我将其值设置为match_parent,则仅此按钮将填满整个屏幕。
因此,如何使用layout_height解决此问题,是否有一些解决方法,还是为网格制作多个LinearLayouts更好?如果您还有其他问题,请随时提出,以便我解释。
这是子级LinearLayout和GridLayout xml代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@color/colorLight"
android:orientation="horizontal">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="8"
android:background="@color/colorLight"
android:>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句