public LinearLayoutStick weight(float weight) { lp().weight = weight; return this; }
/** * Choose the right builder stick according to layout params type * * @param layoutParamsType say {@link android.widget.LinearLayout.LayoutParams} * @param useExistingLayoutParams if true, no LayoutParams will be instantiated * @param width if not useExistingLayoutParams, new LayoutParams will use this as its width * @param height if not useExistingLayoutParams, new LayoutParams will use this as its height * @param <LP> the LayoutParam generic type * @return the corresponding builder stick */ private <LP extends ViewGroup.LayoutParams> Chopstick isInLayout(Class<LP> layoutParamsType, boolean useExistingLayoutParams, int width, int height){ LP lp = useExistingLayoutParams ? useExistingLayoutParams(layoutParamsType) : useNewLayoutParams(layoutParamsType, width, height); if (RelativeLayout.LayoutParams.class.equals(layoutParamsType)) { return new RelativeLayoutStick((RelativeLayout.LayoutParams) lp, mView); } else if(LinearLayout.LayoutParams.class.equals(layoutParamsType)){ return new LinearLayoutStick((LinearLayout.LayoutParams)lp, mView); } throw new UnsupportedOperationException("This Layout is not currently supported. A PR is welcome!"); }
/** * @param gravities can be one or more in: <br> * {@link android.view.Gravity#TOP}<br> * {@link android.view.Gravity#BOTTOM}<br> * {@link android.view.Gravity#CENTER}<br> * {@link android.view.Gravity#CENTER_VERTICAL}<br> * {@link android.view.Gravity#CENTER_HORIZONTAL}<br> * {@link android.view.Gravity#LEFT}<br> * {@link android.view.Gravity#RIGHT}<br> * {@link android.view.Gravity#START}<br> * {@link android.view.Gravity#END}<br> * {@link android.view.Gravity#FILL}<br> * {@link android.view.Gravity#FILL_HORIZONTAL}<br> * {@link android.view.Gravity#FILL_VERTICAL}<br> * {@link android.view.Gravity#CLIP_HORIZONTAL}<br> * {@link android.view.Gravity#CLIP_VERTICAL}<br> * {@link android.view.Gravity#NO_GRAVITY}<br> * @return this * @see <a href="http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:gravity">android:gravity</a> */ public LinearLayoutStick gravity(int... gravities) { int gravity = 0; for (int g : gravities) { gravity |= g; } //noinspection ResourceType lp().gravity = gravity; return this; }