Android布局小案例——安卓版计算器

以此来推,如果还不理解那就看代码吧(表达能力不是很好O(∩_∩)O哈哈~)!

代码部分:

activity_main.xml中:

<TableLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/TableLayout1”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:stretchColumns=“*” >

<TextView

android:id=“@+id/text”

android:layout_width=“match_parent”

android:layout_height=“150dp”

android:background=“@android:color/holo_blue_bright”

android:textSize=“20dp”

android:gravity=“center|right”

android:text=“” />

<TableRow

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1” >

<Button

android:id=“@+id/btn01”

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:text=“C” />

<Button

android:id=“@+id/btn02”

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:text=“←” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“%”

android:text=“%” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“÷”

android:text=“÷” />

<TableRow

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1” >

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“7”

android:text=“7” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“8”

android:text=“8” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“9”

android:text=“9” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“x”

android:text=“x” />

<TableRow

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1” >

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“4”

android:text=“4” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“5”

android:text=“5” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“6”

android:text=“6” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“-”

android:text=“-” />

<TableRow

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1” >

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“1”

android:text=“1” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“2”

android:text=“2” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“3”

android:text=“3” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“+”

android:text=“+” />

<TableRow

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_weight=“1” >

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“.”

android:text=“.” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:onClick=“fun”

android:tag=“0”

android:text=“0” />

<Button

android:id=“@+id/btn19”

android:layout_width=“wrap_content”

android:layout_height=“match_parent”

android:layout_span=“2”

android:text=“=” />

MainActivity.java类:

package com.example.tablelayoutjsq;

import java.util.ArrayList;

import java.util.List;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

public class MainActivity extends Activity {

private TextView text;

private Button btn01;

private Button btn02;

private Button btn19;

String str; //文本值

String str1 = “”; //加减乘除等式

写在最后

很多人在刚接触这个行业的时候或者是在遇到瓶颈期的时候,总会遇到一些问题,比如学了一段时间感觉没有方向感,不知道该从哪里入手去学习,对此我整理了一些资料

如果你熟练掌握以下列出的知识点,相信将会大大增加你通过前两轮技术面试的几率!这些内容都供大家参考,互相学习。

①「Android面试真题解析大全」PDF完整高清版+②「Android面试知识体系」学习思维导图压缩包,最后觉得有帮助、有需要的朋友可以点个赞

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

觉得有帮助、有需要的朋友可以点个赞

[外链图片转存中…(img-gOGwEVIm-1714405392186)]

[外链图片转存中…(img-sSFE16dY-1714405392187)]

[外链图片转存中…(img-oHLNmppf-1714405392187)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 12
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值