【发布时间】:2017-11-10 07:38:32
【问题描述】:
我正在开发一个 Android 应用来显示仪表。有不同类型的仪表(gauge1.xml、gauge2.xml 之类的)。 我想要做的是使用 JSON 数组将不同类型的仪表 layout xml 文件加载到主网格视图。
每个 Grid 单元格根据 JSON 对象包含不同的布局。
我的 JSON 对象:
{"user1": [{"ui": "gauge", "id": "gauge1", "value": 69}, {"ui":
"gauge", "id": "gauge2", "value": 23}]}
Gauge1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<pl.pawelkleczkowski.customgauge.CustomGauge
android:id="@+id/gauge1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
app:gaugePointStartColor="@color/md_red_500"
app:gaugePointEndColor="@color/md_red_500"
app:gaugePointSize="6"
app:gaugeStartAngle="135"
app:gaugeStrokeCap="ROUND"
app:gaugeStrokeColor="@color/md_grey_400"
app:gaugeStrokeWidth="10dp"
app:gaugeStartValue="0"
app:gaugeEndValue="1000"
app:gaugeSweepAngle="270" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/gauge1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="256"
android:textSize="20dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="Temp"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
我该怎么做?
我正在使用pkleczko's CustomGauge 作为仪表。
【问题讨论】:
标签: android xml android-layout android-gridview