package org.itsnat.droid.impl.xmlinflater.layout.attr.view; import android.view.View; import android.widget.LinearLayout; import org.itsnat.droid.impl.dom.DOMAttr; import org.itsnat.droid.impl.xmlinflater.layout.AttrLayoutContext; import org.itsnat.droid.impl.xmlinflater.layout.PendingViewPostCreateProcess; import org.itsnat.droid.impl.xmlinflater.layout.classtree.ClassDescViewBased; import org.itsnat.droid.impl.xmlinflater.shared.attr.AttrDesc; /** * Created by jmarranz on 30/04/14. */ public class AttrDescView_view_View_layout_weight extends AttrDesc<ClassDescViewBased,View,AttrLayoutContext> { public AttrDescView_view_View_layout_weight(ClassDescViewBased parent) { super(parent,"layout_weight"); } @Override public void setAttribute(final View view, DOMAttr attr, AttrLayoutContext attrCtx) { final float weight = getFloat(attr.getResourceDesc(),attrCtx.getXMLInflaterContext()); Runnable task = new Runnable(){ @Override public void run() { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams(); params.weight = weight; }}; PendingViewPostCreateProcess pendingViewPostCreateProcess = attrCtx.getPendingViewPostCreateProcess(); if (pendingViewPostCreateProcess != null) { pendingViewPostCreateProcess.addPendingLayoutParamsTask(task); } else { task.run(); PendingViewPostCreateProcess.onChangedLayoutParams(view); } } @Override public void removeAttribute(View view, AttrLayoutContext attrCtx) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams(); params.weight = 0; PendingViewPostCreateProcess.onChangedLayoutParams(view); } }