Is GridLayout supported by proteus? If not then what is an alternative?

早过忘川 提交于 2019-12-13 03:45:14

问题


I'm trying to use GridLayout in json like this
{ "type": "GridLayout", "android": "http://schemas.android.com/apk/res/android", "orientation": "horizontal", "layout_width": "match_parent", "layout_height": "match_parent", "columnCount": "2", "rowCount": "2", "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" } ] } I'm getting null when I am preparing a ProteusView .

If proteus does not support GridLayout, is there a way to use LinearLayout or RelativeLayout to get the same result


回答1:


Proteus currently does NOT have an implementation for GridLayout; but you can implement the parser for GridLayout yourself and use it. Checkout an example of a custom parser called CircleViewParser and how to register it.

Alternatively, you can use LinearLayout with layout_weight.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="One" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Two" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Three" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Four" />

    </LinearLayout>

</LinearLayout>


来源:https://stackoverflow.com/questions/56984763/is-gridlayout-supported-by-proteus-if-not-then-what-is-an-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!