本来是想用相对布局来写计算器的布局,然后莫名其妙的变成了线性布局,心塞。
- 上代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_height="10dp"
android:layout_width="match_parent"
android:layout_weight="0.4">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Calculate布局实现"
android:textColor="#1FC8F8"
android:id="@+id/mainTextView1"
android:textSize="17sp"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:hint="请输入计算"
android:textSize="40sp"
android:text="计算输出口"/>
</RelativeLayout>
<TextView
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#000000"/>
<LinearLayout
android:layout_height="40dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1.0"
android:gravity="center"
android:layout_marginTop

本文介绍了如何使用线性布局(LinearLayout)实现计算器的界面布局。首先采用一个垂直方向的LinearLayout,内部包含一个相对布局和另一个垂直LinearLayout。相对布局中设置控件,并探讨了控件属性对布局的影响。接着在下层LinearLayout中添加多个Button。作者强调LinearLayout的垂直和平行属性,理解这一点对布局至关重要。在布局过程中遇到的问题和解决方法也进行了分享,提倡动手实践和尝试不同布局以优化代码和提高效率。
最低0.47元/天 解锁文章
4930

被折叠的 条评论
为什么被折叠?



