花了我整整四个小时呀
慕课网的Android基础 第一部的最后检测是一个计算器
天杀的 按照视频讲解用Linearlayout布局怎么都搭不出来 我真的是要疯了
然后查百度google 恨不得把所有布局都用上有没有
最后终于还是让我搭起来了
虽然很丑有没有
不多说先上图
一开始发现在AS里做出来的布局一到模拟机上就变小变歪
重写了好多遍
最后用了
layout_weight 果断解决了有没有 汗 真的累 虽然很低端但是真的很有成就感呀~~~~~
以下是代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<EditText
android:layout_weight="1"
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical|right"
android:textSize="25sp"
android:hint="type something"
android:background="@drawable/bg"
android:textColor="#010101" />
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="6"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp">
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/linearLayout"
android:focusableInTouchMode="true" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="C"
android:layout_weight="1"
android:id="@+id/button"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="DEL"
android:layout_weight="1"
android:id="@+id/button2"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="÷"
android:layout_weight="1"
android:id="@+id/button3"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="×"
android:layout_weight="1"
android:id="@+id/button4"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/linearLayout2" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="7"
android:layout_weight="1"
android:id="@+id/button5"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="8"
android:layout_weight="1"
android:id="@+id/button6"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="9"
android:layout_weight="1"
android:id="@+id/button7"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="+"
android:layout_weight="1"
android:id="@+id/button8"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/linearLayout3" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="4"
android:layout_weight="1"
android:id="@+id/button9"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="5"
android:layout_weight="1"
android:id="@+id/button10"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="6"
android:layout_weight="1"
android:id="@+id/button11"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="-"
android:layout_weight="1"
android:id="@+id/button12"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_weight="2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/linearLayout4" >
<LinearLayout
android:layout_weight="3"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent" >
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="1"
android:layout_weight="1"
android:id="@+id/button13"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="2"
android:layout_weight="1"
android:id="@+id/button14"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="3"
android:layout_weight="1"
android:id="@+id/button15"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="0"
android:layout_weight="2"
android:id="@+id/button16"
android:background="@drawable/bg"
android:textSize="25sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="."
android:layout_weight="1"
android:id="@+id/button17"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="match_parent" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="="
android:layout_weight="1"
android:id="@+id/button18"
android:background="@drawable/bg"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
下面是背景图的代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#FFB3FCF6"
/>
<corners
android:radius="5dp"
/>
<stroke
android:width="2dp"
android:color="#000000"
/>
</shape>
记录一下 真的累 第一次这么早想睡觉 ~~加油