/// <summary> /// Sets (or replaces) the /// <see cref="Drawable">Drawable</see> /// for the layer with the given id. /// </summary> /// <param name="id">The layer ID to search for.</param> /// <param name="drawable"> /// The replacement /// <see cref="Drawable">Drawable</see> /// . /// </param> /// <returns> /// Whether the /// <see cref="Drawable">Drawable</see> /// was replaced (could return false if /// the id was not found). /// </returns> public virtual bool setDrawableByLayerId(int id, android.graphics.drawable.Drawable drawable) { android.graphics.drawable.LayerDrawable.ChildDrawable[] layers = mLayerState.mChildren; { for (int i = mLayerState.mNum - 1; i >= 0; i--) { if (layers[i].mId == id) { if (layers[i].mDrawable != null) { if (drawable != null) { android.graphics.Rect bounds = layers[i].mDrawable.getBounds(); drawable.setBounds(bounds); } layers[i].mDrawable.setCallback(null); } if (drawable != null) { drawable.setCallback(this); } layers[i].mDrawable = drawable; return true; } } } return false; }
/// <param name="gap"> /// If set to /// <see cref="int.MinValue">int.MinValue</see> /// , this will be ignored and /// </param> private void setThumbPos(int w, android.graphics.drawable.Drawable thumb, float scale , int gap) { int available = w - mPaddingLeft - mPaddingRight; int thumbWidth = thumb.getIntrinsicWidth(); int thumbHeight = thumb.getIntrinsicHeight(); available -= thumbWidth; // The extra space for the thumb to move on the track available += mThumbOffset * 2; int thumbPos = (int)(scale * available); int topBound; int bottomBound; if (gap == int.MinValue) { android.graphics.Rect oldBounds = thumb.getBounds(); topBound = oldBounds.top; bottomBound = oldBounds.bottom; } else { topBound = gap; bottomBound = gap + thumbHeight; } // Canvas will be translated, so 0,0 is where we start drawing thumb.setBounds(thumbPos, topBound, thumbPos + thumbWidth, bottomBound); }
public void setIcon(android.graphics.drawable.Drawable icon) { mIcon = icon; if (icon != null) { icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); // Set the compound drawables setCompoundDrawables(null, icon, null, null); // When there is an icon, make sure the text is at the bottom setGravity(android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL); requestLayout(); } else { setCompoundDrawables(null, null, null, null); // When there is no icon, make sure the text is centered vertically setGravity(android.view.Gravity.CENTER_VERTICAL | android.view.Gravity.CENTER_HORIZONTAL ); } }