标签:ack getch top for protected sla idg idt attr
交叉布局
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; /** * 作者:南宫燚滨 * 描述:交叉布局 * 邮箱:nangongyibin@gmail.com * 时间: 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
标签:ack getch top for protected sla idg idt attr
原文地址:https://www.cnblogs.com/nangongyibin/p/10324263.html