首页 > 编程知识 正文

android五种布局,android水平布局

时间:2023-05-03 10:01:12 阅读:172524 作者:2172

作者:XINHAO_HAN

安卓没有系统本身给我们带来的布局、流媒体和布局。 要写这个效果,必须在RelativeLayout中实现,或者在其他布局中实现。 但问题是,怎么方便、麻烦、省事,还是自己写比较好。

代码非常简单,一共只有100行左右。 只是简单地实现,要使用项目中使用的香蕉砖,需要做一些修改。

Warning:的当前布局至少需要一个子布局

效果图:

1521700893541mzflow.gif

代码:

package com.example.xinhao _ Han.xh flowlayout

import android.content.Context

import Android.util.attributes et

import android.util.Log

import android.view.ViewGroup

//*

* createdbyadministratoron 2017/6/6。

*/

/*

*

*径流布局,XINHAO_HAN

*/

class flowlayout : view组{

var conutSize: Int=0

constructor (上下文:上下文? ) : super (上下文) )。

constructor (上下文:上下文?attrs: AttributeSet? ) :super(context,attrs ) ) ) )。

constructor (上下文:上下文?attrs: AttributeSet?defstyleattr : int (: super (context,attrs,defstyleattr ) )。

//测量位置

overridefunonlayout (changed : boolean,l: Int,t: Int,r: Int,b: Int ) ) )。

/*

*

*表示目前没有孩子

*/

if(childcount==0) {

返回

}

//记录现在所有孩子的宽度

var childWei: Int=0

//记录现在孩子多的高度

var childHei: Int=0

//记录多少行

var cout: Int=0

Log.e ('屏幕宽度',' ' UIUtils.getWeiSize ) )

for(Iin0.childcount-1 ) {

valchildat=getchildat(I ) )。

valwidthmeasurespec=measurespec.makemeasurespec (0,MeasureSpec.UNSPECIFIED ) )。

valheightmeasurespec=measurespec.makemeasurespec (0,MeasureSpec.UNSPECIFIED ) )。

childat.measure (widthmeasurespec,heightMeasureSpec ) )。

//加上现在孩子的宽度和高度

Log.e (测量结果)、(childWei ) )。

if(ChildWeiuiutils.getweisize () () ) ) )

一行的大小正好是方形,放不下就放下一行。 没有问题

if(I==0) ) )。

childat.layout(0,) cout * childAt.measuredHeight )、childWei childAt.measuredWidth )、cout*childat.measured

else {

childweichildat.measuredwidthuiutils.getweisize (() ) 0

(这一行已经来不及吐槽了,表示让给下一行

出局

//记得下一行的位置记录从0开始

childWei=0

childat.layout(childWei,(cout * childAt.measuredHeight ),childWei childAt.measuredWidth ) * cout * childat.measuat

} else {

childat.layout(childWei,(cout * childAt.measuredHeight ),childWei childAt.measuredWidth ) * cout * childat.measuat

}

}

childWei =childAt.measuredWidth

} else {

//不能放置一行。 需要换行

//记录行数

出局

//重新记录行数

childWei=0

}

}

conutSize=cout

}

//测量大小,根据现在孩子的View决定自己的大小

overridefunonmeasure (widthmeasurespec : int,heightMeasureSpec: Int ) {

/*

*

*表示目前没有孩子

*/

if(childcount==0) {

返回

}

var cout: Int=0

//记录现在所有孩子的宽度

var childWei: Int=0

//记录现在孩子多的高度

var childHei: Int=0

for(Iin0.childcount-1 ) {

valchildat=getchildat(I ) )。

childat.measure (widthmeasurespec,heightMeasureSpec ) )。

//加上现在孩子的宽度和高度

childWei =childAt.measuredWidth

child hei=childat.measured height

}

if(ChildWeiuiutils.getweisize () () ) ) )

childWei=UIUtils.getWeiSize (

} else {

}

super.on measure (measurespec.makemeasurespec ) ChildWei,MeasureSpec.EXACTLY ),heightMeasureSpec ) ) )。

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。