gpt4 book ai didi

android - 扩展网格布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:31 25 4
gpt4 key购买 nike

对于 GridLayout,这是一个有效的布局定义。没有关于的警告应定义“layout_height”属性应定义“layout_width”属性

<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</GridLayout>

另一方面,如果我扩展 GridLayout,等效布局会同时给出警告 'layout_height' attribute should be defined'layout_width' attribute should be defined

<ExtendedGridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</ExtendedGridLayout>

这是扩展的网格布局的样子

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);
}
}

我试着浏览 GridLayout源,他们所做的似乎是扩展 ViewGroup.LayoutParams 并设置默认宽度和高度,就像 PercentRelativeLayout 一样

因此看起来应该基于继承,ExtendedGridLayout 还应该为其子项设置默认宽度和高度,或者执行 GridLayout 所做的任何操作以避免布局编辑器中的警告消息。

所以我的问题是为什么 ExtendedGridLayout 有警告,我该如何防止?

最佳答案

这是 AndroidStudio 的默认行为。
避免该错误的一种方法是抑制。

<ExtendedGridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--suppress AndroidDomInspection -->
<ImageView />

</ExtendedGridLayout>

AndroidStudio 跳过显示 GridLayout 的错误,但不会跳过 GridLayout 的子项。这是 the source code AndroidStudio 的检查员。

这里是 related bug report .
通过此错误报告,您的问题发生了 this .

关于android - 扩展网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38341655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com