Created
July 20, 2013 21:50
-
-
Save scottdweber/6046548 to your computer and use it in GitHub Desktop.
An extended RelativeLayout that fixes layout issues when the size of the layout is inexact (that is, wrap_content) and you want to base the positioning of one or more child views on the positioning of another child view that is itself positioned by layout_centerInParent, layout_centerHorizontal or layout_centerVertical. It is clearly not efficie…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2013 Scott Weber | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.scottweber.widget; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.widget.RelativeLayout; | |
public class DoubleMeasureRelativeLayout extends RelativeLayout { | |
public DoubleMeasureRelativeLayout(Context context) { | |
super(context); | |
} | |
public DoubleMeasureRelativeLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public DoubleMeasureRelativeLayout(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY | |
|| MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) { | |
super.onMeasure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), | |
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment