交叉布局
Posted nangongyibin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了交叉布局相关的知识,希望对你有一定的参考价值。
交叉布局
package ngyb.crossover; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; /** * 作者:南宫燚滨 * 描述:交叉布局 * 邮箱:[email protected] * 时间: 2018/4/18 14:30 */ public class NGYBCrossLayout extends RelativeLayout { private static final String TAG = "CrossLayout"; private boolean isLeft; public NGYBCrossLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int top = 0; for (int i = 0; i < getChildCount(); i++) { View childAt = getChildAt(i); int left = 0; if (isLeft){ if (i%2==0){ left =getMeasuredWidth()-childAt.getMeasuredWidth(); }else{ left = 0; } }else{ if (i%2==0){ left =0; }else{ left = getMeasuredWidth()-childAt.getMeasuredWidth(); } } int right = left+childAt.getMeasuredWidth(); int bottom = top+childAt.getMeasuredHeight(); Log.e(TAG, "onLayout: "+left+"="+right+"="+top+"="+bottom ); childAt.layout(left,top,right,bottom); top+=childAt.getMeasuredHeight(); } } public void change() { isLeft = !isLeft; requestLayout(); } }
https://github.com/nangongyibin7219/Android_CrossLayout
以上是关于交叉布局的主要内容,如果未能解决你的问题,请参考以下文章