onMeasure()をオーバーライドする信頼できる方法は?
onMeasure()をオーバーライドする正しい方法は何ですか?私はさまざまなアプローチを見てきました。たとえば、Professional Android Developmentは、MeasureSpecを使用してディメンションを計算し、setMeasuredDimension()の呼び出しで終了します。例えば: @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ int parentWidth = MeasureSpec.getSize(widthMeasureSpec); int parentHeight = MeasureSpec.getSize(heightMeasureSpec); this.setMeasuredDimension(parentWidth/2, parentHeight); } 一方、この投稿によると、「正しい」方法は、MeasureSpecを使用し、setMeasuredDimensions()を呼び出し、続いてsetLayoutParams()を呼び出し、最後にsuper.onMeasure()を呼び出すことです。例えば: @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ int parentWidth = MeasureSpec.getSize(widthMeasureSpec); int parentHeight = MeasureSpec.getSize(heightMeasureSpec); this.setMeasuredDimension(parentWidth/2, parentHeight); this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } では、どちらが正しい方法ですか?どちらのアプローチも私にとって100%うまくいきませんでした。 私が本当に求めているのは、onMeasure()、レイアウト、子ビューの寸法などを説明するチュートリアルを知っている人はいると思いますか?