1.布局
首先我们知道实现的功能之后,并不是要去马上实现功能,因为这不是控制台,而是界面交互,那么我们得先写好界面,再去做功能相关的东西,如果有人分工,那就再好不过了,一个写界面,一个写功能,很快就写完了,当然这就涉及文档了,因为你们的变量名称,id名称要保持一致,不然修修改改有时一年。
1.1.效果
把四个按钮放在最顶端,然后下面是ListView,列表显示内容。
1.2.代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_add_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn_add_one_name"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/btn_delete_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="5dp"
android:text="@string/btn_delete_one_name"
tools:ignore="ButtonStyle"/>
<Button
android:id="@+id/btn_delete_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="5dp"
android:text="@string/btn_delete_all_name"
tools:ignore="ButtonStyle"/>
<Button
android:id="@+id/btn_up_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="5dp"
android:text="@string/btn_up_one_name"
tools:ignore="ButtonStyle"/>
</LinearLayout>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"/>
</LinearLayout>
1.3.注意事项
一定要给按钮和列表添加id,其他的无关紧要,但是不加id,相当于这个按钮白加进去了,没法使用,记住你要用到的按钮或者控件都要加上id。