小编Bar*_*ock的帖子

Android - View.requestLayout在OnLayoutChangeListener中不起作用

我必须使用GridLayout我的应用程序.问题GridLayout是体重的限制因此我必须在运行时缩放其子项大小.我是在一个人的帮助下做到的OnGlobalLayoutListener.

我的孩子GridLayout是两个孩子Button,有父母的宽度和父母身高的一半.一个Button在上面,一个Button在下面.如果Button单击鞋面,我想将GridLayout宽度和高度的大小切换为500,宽度和高度的大小为700.点击在上部后ButtonButtonS的关系具有正确的尺度,但他们没有这样做.

public class HauptAktivitaet extends Activity implements OnLayoutChangeListener, OnClickListener{

  /** ContentView its sizes I will change on a click later */

  private GridLayout mGridLayout;

  /** LayoutParams of the above child */

  private GridLayout.LayoutParams mGridLayout_LayoutParams_Above;

  /** LayoutParams of the below child */

  private GridLayout.LayoutParams mGridLayout_LayoutParams_Below;

  /** Children of the ContentView */

  private Button mButtonAbove;
  private Button mButtonBelow;


  @Override …
Run Code Online (Sandbox Code Playgroud)

java layout android viewgroup

7
推荐指数
2
解决办法
7230
查看次数

如何在Canvas后面设置CustomView的背景?

我有这样的习惯View:

public class ShadowTextView extends TextView {

...

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        final int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
        final int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
        final int minSize = Math.min(parentWidth, parentHeight);

        mShadow = new Paint(Paint.ANTI_ALIAS_FLAG);

        RadialGradient gradient = new RadialGradient(
                parentWidth * mCenterX,
                parentHeight * mCenterY,
                minSize * mGradientRadiusWidthPercent,
                new int[]{mStartColor, mCenterColor, mEndColor},
                null,
                android.graphics.Shader.TileMode.CLAMP);

        mShadow.setDither(true);
        mShadow.setShader(gradient);

    }

    @Override
    protected void onDraw(Canvas canvas) {

        super.onDraw(canvas);

        canvas.drawRect(0, 0, getWidth(), getHeight(), mShadow);

    }

...

}
Run Code Online (Sandbox Code Playgroud)

在XML格式中,我希望将它CustomView …

android background canvas android-custom-view

1
推荐指数
1
解决办法
4717
查看次数