流式布局
来源:互联网 发布:数据库关键字查询 编辑:程序博客网 时间:2024/06/08 20:11
自定义一个控件 使这个控件中的所有子控件按照自己的想法和需求排列<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 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" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.liushi.MainActivity"><com.example.liushi.liu android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="今天是个好日子" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="心想的事儿都能成" /></com.example.liushi.liu></android.support.constraint.ConstraintLayout>
//////////////////////////////////////////////////////////////////////////////////////////////package com.example.jingdong.zdyview;import android.content.Context;import android.graphics.Canvas;import android.util.AttributeSet;import android.view.View;import android.view.ViewGroup;/** * Created by Administrator on 2017/12/16 0016. */public class LiuShi extends ViewGroup { public LiuShi(Context context) { this(context,null); } public LiuShi(Context context, AttributeSet attrs) { this(context, attrs,0); } public LiuShi(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //测量 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //测量子view measureChildren(widthMeasureSpec,heightMeasureSpec); } //绘制的方法 @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { //初始化子view的宽高 int wid=0; int hei=0; //得到子view的个数 int childcount=getChildCount(); for(int i=0;i<childcount;i++) { //得到这个viewgroup里面的每一个子view View childView=getChildAt(i); //得到每一个子view的宽高 int width=childView.getMeasuredWidth(); int height=childView.getMeasuredHeight(); //确定子view的高度 childView.layout(wid,hei,width,hei+height); //累加所有子view宽高 wid=width; hei+=height; } }}
阅读全文
0 0
- GUI布局:边界布局、流式布局、网格布局、卡片布局
- Java_流式布局、边框布局以及网格布局
- 流式布局、浮动布局及绝对定位布局
- 流式布局,标签式布局
- Java_GUI_布局_流式布局
- 网站布局中的瀑布流式布局
- 固定布局与流式布局
- 练习---流式布局和网格布局
- java布局——流式布局
- 自定义布局VerticalView(倒置流式布局)
- css sticky footer布局+流式布局
- 流式布局
- html流式布局
- 拥抱流式布局
- 流式布局 RadioGroup
- 流式布局
- FlowLayout流式布局
- 流式布局
- 字符串匹配的KMP算法_阮一峰
- Easyui实例--tree组件的使用2
- js获取链接地址后的参数
- autoquad源码分析1
- 支付宝、财付通、网银、百度钱包、京东钱包接口费率
- 流式布局
- 【missing data】Imputation realization in Python (Implementation)
- YAML 语言教程
- EL表达式取Map,List值的总结
- python -- 序列和之差的绝对值最小
- C++ double类型的数转换成具体的日期和时间
- 20个css使用的高级技巧
- matlab-isnan function
- 决斗场