我正在尝试使用 Proteus充气GridLayout
。FrameLayout
我尝试按照这里的建议实施GridLayoutParser
and - Proteus 支持 GridLayout 吗?如果不是,那么有什么替代方案?.GridLayout
这是我尝试过的-
查看-
public class ProteusGridLayout extends GridLayout implements ProteusView {
private ProteusViewManager viewManager;
public ProteusGridLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ProteusGridLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusGridLayout(Context context) {
super(context);
}
public ProteusGridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public ProteusViewManager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(ProteusViewManager proteusViewManager) {
viewManager = proteusViewManager;
}
}
解析器 -
public class ProteusGridLayoutParser extends WrappableParser<ProteusGridLayout> {
public ProteusGridLayoutParser(Parser<ProteusGridLayout> wrappedParser) {
super(wrappedParser);
}
@Override
public ProteusView createView(ViewGroup parent, JsonObject layout, JsonObject data, Styles styles, int index) {
return new ProteusGridLayout(parent.getContext());
}
}
我试图渲染的 Proteus json 数据 -
{
"type": "GridLayout",
"layout_width": "match_parent",
"layout_height": "match_parent",
"layout_gravity": "fill_horizontal",
"columnCount": "2",
"useDefaultMargins": "true",
"children": [{
"type": "TextView",
"layout_width": "wrap_content",
"layout_height": "wrap_content",
"layout_columnWeight": "1",
"layout_marginTop": "8dp",
"layout_marginLeft": "16dp",
"textSize": "20dp",
"textColor": "@android:color/background_dark",
"text": "244536"
},
{
"type": "TextView",
"layout_width": "wrap_content",
"layout_height": "wrap_content",
"layout_columnWeight": "1",
"layout_marginTop": "8dp",
"layout_marginLeft": "16dp",
"textSize": "20dp",
"textColor": "@android:color/background_dark",
"text": "244536"
},
{
"type": "TextView",
"layout_width": "wrap_content",
"layout_height": "wrap_content",
"layout_columnWeight": "1",
"layout_marginTop": "8dp",
"layout_marginLeft": "16dp",
"textSize": "20dp",
"textColor": "@android:color/background_dark",
"text": "244536"
}
]
}
我在 logcat - 中得到了这个D/android.widget.GridLayout: horizontal constraints: x3-x0>=660, x3-x2<=164, x2-x1<=164, x1-x0<=164 are inconsistent; permanently removing: x3-x2<=164.
。GridLayout 未正确呈现,三个元素像 LinearLayout 一样出现在一行中。