第57篇 Android Studio实现油耗记录App(二)主界面布局

第57篇 Android Studio实现油耗记录App(二)主界面布局

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。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大唐不良猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值