如何实不写代码实现android应用
是一套基于一整套开发框架实现的基于databinding实现不需要写java代码来实现简单的应用。
可以实现大部分页面功能,历时两周实现此功能。等待在项目只实践,如有补充欢迎提出。转载请标明出处。
测试apk其中 ”自动frame测试“ 按钮点击后的所有内容即为本文中的代码实现
点击下载 https://pan.baidu.com/s/1nvonPrz
- 实现登陆页面,实现登陆并进入下一个页面。登陆需要输入3个参数 门店名称,账号,密码,其中账号必须是数字,密码需要转换为md5。
<?xml version="1.0" encoding="UTF-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="F"
type="com.mdx.framework.autofit.AutoFit" />
<variable
name="P"
type="java.util.HashMap" />
<import type="com.udows.canyin.proto.ApisFactory"></import>
<import type="com.mdx.framework.commons.verify.Md5"></import>
</data>
<com.mdx.framework.autofit.layout.FitLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/store"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="002@458996"
android:textSize="20sp" />
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="001"
android:textSize="20sp" />
<EditText
android:id="@+id/psw"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="123456"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登陆"
android:onClick='@{(v)->F.save(ApisFactory.getApiEmpLogin().set((String)F.V(@id/store),(String)F.V(@id/name,F.NUM,"门店"),Md5.mD5((String)F.V(@id/psw)),"android","111111111"),"@user").CKERR().close().startActivity(@layout/frg_autofittest,F.CV("state","1"))}'/>
</com.mdx.framework.autofit.layout.FitLinearLayout>
</layout>
-** 布局中主要绑定登陆按钮的事件解释如下。
(String)F.V(@id/name,F.NUM,"门店") //获取name的值,验证器使用NUM即数字验证器,提示字段为门店
F.save(...,"@user") //获取接口数据并保存,第一个参数为接口类,@user为保存数据名@是全局保存,全局保存后可以在任意位置获取此参数。
CKERR() //验证接口错误,如果有错误则中断执行,否则向下执行
close() //关闭当前页面
.startActivity() //打开新的页面,新的页面加载@layout/frg_autofittest这个布局,并且传递F.CV("state","1") state 和1 的参数
-** 显示效果如下
-** 点击后进入列表页。页面是一个列表页是显示一个根据服务器数据显示的一个列表。有筛选功能。
<?xml version="1.0" encoding="UTF-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="item"
type="com.mdx.framework.server.api.base.Msg_Update" />
<variable
name="F"
type="com.mdx.framework.autofit.AutoFit" />
<variable
name="P"
type="java.util.HashMap" />
<import type="com.udows.canyin.proto.ApisFactory"></import>
<import type="com.mdx.framework.commons.verify.Md5"></import>
</data>
<com.mdx.framework.autofit.layout.FitLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical"
app:saveApi='@{F.listSet(ApisFactory.getApiEmpKcOrders().set((String)P["state"]),@layout/item_kc)}'>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="@{item.url}"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="40dip"
android:gravity="center"
android:onClick="@{(v)->F.dialog(@layout/pop_select)}"
android:text='@{P["flname"]??"all"}'/>
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="40dip"
android:gravity="center"
android:onClick="@{(v)->F.pop(v,@layout/frg_autofittest)}"
android:text='@{P["flname"]??"all"}'/>
</LinearLayout>
<com.mdx.framework.widget.pagerecycleview.MFRecyclerView
android:id="@+id/mrecycleview"
android:layout_width="match_parent"
android:layout_height="300dip"
android:minHeight="200dip"
android:layout_weight="1"
app:column="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dip">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.mdx.framework.widget.MImageView
android:id="@+id/icon1"
android:layout_width="25dip"
android:layout_height="22dip"
android:src="@mipmap/tylt_bt_shouye_n" />
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:text="首页"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.mdx.framework.widget.MImageView
android:id="@+id/icon2"
android:layout_width="25dip"
android:layout_height="22dip"
android:src="@mipmap/tylt_bt_feilei_n" />
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:text="分类"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.mdx.framework.widget.MImageView
android:id="@+id/icon4"
android:layout_width="25dip"
android:layout_height="22dip"
android:src="@mipmap/tylt_bt_luntan_n" />
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:text="论坛"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.mdx.framework.widget.MImageView
android:id="@+id/icon3"
android:layout_width="25dip"
android:layout_height="22dip"
android:src="@mipmap/tylt_bt_wo_n" />
<TextView
android:id="@+id/txt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:text="我的"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</com.mdx.framework.autofit.layout.FitLinearLayout>
</layout>
- ** 核心实现代码功能为
'@{F.listSet(ApisFactory.getApiEmpKcOrders().set((String)P["state"]),@layout/item_kc)}
F.listSet(ApiUpdate,res) //为页面中的list设置接口类,和显示的cell的形式
P["state"] //取页面传递以及接口设置的参数,如需要区全局的可以使用@前缀
@{(v)->F.dialog(@layout/pop_select) //弹出 @layout/pop_select 布局的dialog
@{(v)->F.pop(v,@layout/pop_select) //弹出 @layout/pop_select 布局的popwindow
- **筛选布局窗口 主要功能弹出多种状态,点击后关闭弹出框并且传递参数给列表并刷新。
<?xml version="1.0" encoding="UTF-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="F"
type="com.mdx.framework.autofit.AutoFit" />
<variable
name="P"
type="java.util.HashMap" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TextView
android:id="@+id/state_all"
android:layout_width="match_parent"
android:layout_height="40dip"
style="@style/kcxdselectpop"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","0","flname","all").close()}'
android:text="全部" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_dfk"
android:layout_width="match_parent"
android:layout_height="40dip"
style="@style/kcxdselectpop"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","1","flname","dfk").close()}'
android:text="待付款" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_djd"
android:layout_width="match_parent"
android:layout_height="40dip"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","2","flname","djd").close()}'
style="@style/kcxdselectpop"
android:text="待接单" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_yjd"
android:layout_width="match_parent"
android:layout_height="40dip"
style="@style/kcxdselectpop"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","3","flname","yjd").close()}'
android:text="已接单" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_yjud"
android:layout_width="match_parent"
android:layout_height="40dip"
style="@style/kcxdselectpop"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","4","flname","ysd").close()}'
android:text="已拒单" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_yqx"
android:layout_width="match_parent"
android:layout_height="40dip"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","5","flname","yqx").close()}'
style="@style/kcxdselectpop"
android:text="已取消" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<TextView
android:id="@+id/state_ywc"
android:layout_width="match_parent"
android:layout_height="40dip"
android:onClick='@{()->F.setParams(@layout/frg_autofittest,"state","0","flname","ywc").close()}'
style="@style/kcxdselectpop"
android:text="已完成" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
</LinearLayout>
</layout>
- *核心代码解释如下
'@{()->F.setParams(@layout/frg_autofittest,"state","0","flname","ywc").close()}'
F.setParams(resid,...) //给一个布局传递参数 resid,参数以键值对方式传递。传递后会根据设置刷新页面。
.close() //关闭窗口
- *Cell数据显示如下,显示服务器的数据,并且实现一个点击功能,点击后显示一个loading按钮并且数据加载完成后关闭
<?xml version="1.0" encoding="UTF-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<import type="android.text.TextUtils" />
<variable
name="F"
type="com.mdx.framework.autofit.AutoFit" />
<variable
name="P"
type="java.util.HashMap" />
<variable
name="item"
type="com.udows.canyin.proto.MOrderInfo" />
<variable
name="clickListener"
type="android.view.View.OnClickListener" />
<import type="com.udows.canyin.proto.ApisFactory"></import>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dip"
android:layout_marginTop="10dip"
android:layout_marginLeft="5dip"
android:onClick='@{(v)->F.visable(@id/process_jd,View.VISIBLE).save(ApisFactory.getApiEmpLogin().set("111","111","111","android","111111111"),"@user").visable(@id/process_jd,View.GONE).toast("wancheng")}'
android:layout_marginRight="5dip"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:gravity="top"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@{item.code}"
android:textColor="#262626"
android:textSize="13dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:text="@{item.time}"
android:textColor="#262626"
android:textSize="13dip" />
<TextView
android:id="@+id/state"
style="@style/text_style_11_white"
android:layout_width="52dip"
android:layout_height="25dip"
android:layout_alignParentRight="true"
android:layout_marginRight="5dip"
android:gravity="center_horizontal"
android:paddingTop="3dip"
android:textSize="12dip" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="#eee"></View>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#eee"></View>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text='@{item.desk}'
android:layout_marginRight="100dip"
android:textColor="#262626"
android:textSize="13dip" />
<TextView
android:id="@+id/paystate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="34dp"
android:gravity="center"
android:paddingBottom="2dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="2dip"
android:textSize="10dip" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="bottom"
android:paddingTop="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
android:text="¥"
android:textColor="#e73b3b"
android:textSize="12dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
android:text="@{item.amount}"
android:textColor="#e73b3b"
android:textSize="17dip" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="3dip"
android:gravity="bottom"
android:paddingTop="10dip">
<RelativeLayout
android:id="@+id/btn_td"
android:layout_width="50dip"
android:layout_height="25dip"
android:gravity="center_horizontal|bottom"
android:orientation="vertical"
android:visibility="@{(item.state==2)?View.VISIBLE:View.GONE}">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:singleLine="true"
android:text="拒单"
android:textSize="14dip" />
<ImageView
android:layout_width="50dip"
android:layout_height="2dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dip" />
<ProgressBar
android:id="@+id/process_td"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/btn_jd"
android:layout_width="50dip"
android:layout_height="25dip"
android:layout_marginLeft="15dip"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:singleLine="true"
android:text="接单"
android:textSize="14dip" />
<ImageView
android:layout_width="50dip"
android:layout_height="2dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dip" />
<ProgressBar
android:id="@+id/process_jd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</layout>
-* 其中apiuodate是封装好的接口调用类
-** MFRecyclerView是封装好的recyclerview实现页面的布局显示。 github上可以看到源码。https://github.com/ryanliu19843/pagerecycleview
-** MImageview是封装的imageview 实现图片变色动画显示等。
github上可以看到源码。https://github.com/ryanliu19843/XImageView
测试apk如下其中
”自动frame测试“ 按钮点击后的所有内容即为本文中的代码实现
https://pan.baidu.com/s/1nvonPrz