With GridLayout this is a valid layout definition. There's no warning about
'layout_height' attribute should be defined
or 'layout_width' attribute should be defined
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</GridLayout>
On the otherhand, if I extend GridLayout the equivalent layout gives both warnings 'layout_height' attribute should be defined
and 'layout_width' attribute should be defined
<ExtendedGridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</ExtendedGridLayout>
this is what the extended gridlayout looks like
package com.github.extendedgridlayout;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.GridLayout;
@SuppressWarnings("unused")
public class ExtendedGridLayout extends GridLayout {
public ExtendedGridLayout(Context context){
super(context);
}
public ExtendedGridLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExtendedGridLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ExtendedGridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
I tried looking through the GridLayout
source, and it seems like what they did was to extend ViewGroup.LayoutParams and set a default width and height, just like for PercentRelativeLayout
So it should seem that based off of inheritance, ExtendedGridLayout should also set a default width and height for it's children or do whatever it is that GridLayout does to avoid the warning message in the layout editor.
So my question is why does ExtendedGridLayout
have the warning and how do I prevent it?
LinearLayout
s instead of using uselessGridLayout
. – Verdun