这期内容当中小编将会给大家带来有关android应用中怎么利用onLayout()实现一个流式布的局,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
在onLayout方法中有四个参数,我画了一个简单的图来分清楚值哪里。
包com.example.my_view; 进口android.content.Context; 进口android.util.AttributeSet; 进口android.view.View; 进口android.view.ViewGroup;/* * *自定义布局流布的局 */公开课FlowLayout延伸ViewGroup { 公共FlowLayout(上下文语境){ 超级(上下文); } 公共FlowLayout(上下文语境,AttributeSet attrs) { 超级(上下文,attrs); }/* * * * @param改变 * @param l左 * @param t上 * @param r右 * @param b下 */@Override 保护空白> & lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比; & lt; com.example.my_view.FlowLayout xmlns: android=癶ttp://schemas.android.com/apk/res/android" xmlns:应用=癶ttp://schemas.android.com/apk/res-auto" xmlns:工具=癶ttp://schemas.android.com/tools" android: layout_width=癿atch_parent" android: layout_height=癿atch_parent" 工具:上下文=癱om.example.my_view.MainActivity"比; & lt; ! & lt; com.example.my_view.Counter android: layout_width=癿atch_parent" android: layout_height=皐rap_content" 应用:数量=?0“; 应用:背景=? ff002b" 应用程序:输入textColor=? 0 fd444"/祝辞——比; & lt; !——& lt; TextView android: layout_width=皐rap_content" android: layout_height=皐rap_content" android:文本=拔以谧远ㄒ宀季值南旅妗?祝辞——比; & lt;按钮 android: layout_width=?00 dp" android: layout_height=?0 dp" android:文本=癰utton1"/比; & lt;按钮 android: layout_width=?00 dp" android: layout_height=?00 dp" android:文本=癰utton2"/比; & lt;按钮 android: layout_width=?80 dp" android: layout_height=?0 dp" android:文本=癰utton3"/比; & lt;按钮 android: layout_width=?00 dp" android: layout_height=?0 dp" android:文本=癰utton4"/比; & lt;按钮 android: layout_width=?0 dp" android: layout_height=?00 dp" android:文本=癰utton5"/比; & lt;按钮 android: layout_width=?00 dp" android: layout_height=?0 dp" android:文本=癰utton6"/比; & lt;按钮 android: layout_width=?20 dp" android: layout_height=?0 dp" android:文本=癰utton7"/比; & lt;按钮 android: layout_width=?00 dp" android: layout_height=?0 dp" android:文本=癰utton8"/比; & lt;/com.example.my_view.FlowLayout>
上述就是小编为大家分享的android应用中怎么利用onLayout()实现一个流式布局了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。