两个布局文件
GrainResult.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/SV"
android:orientation="vertical"
android:background="@drawable/side_nav_bar"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
>
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/side_nav_bar"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textviewMemo1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 气温"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewSkyTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMemo2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 气湿"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewSkyHudi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMemo3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 仓温"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewStoreTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMemo4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 仓湿"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewStoreHudi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textviewMemo5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 最高温"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMaxTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMemo6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 最低温"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMinTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewMemo7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 平均温"
android:textColor="#fffafafa"
/>
<TextView
android:id="@+id/textviewAvgTemp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 0.0"
android:textColor="#fffafafa"
/>
</TableRow>
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:id="@+id/GL"
android:orientation="vertical"
>
</GridLayout>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
InCludeGrainResult.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/grainresult" />
</android.support.design.widget.CoordinatorLayout>
两个活动
GrainResult.cs
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.Graphics;
using System.IO;
using Android.Content.Res;
namespace JCFlat
{
[Activity(Label = "粮情检测结果")]
public class GrainResult : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GrainResult);
// Create your application here
}
}
}
InCludeGrainResult.cs
using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Android.Graphics;
using System.IO;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
namespace JCFlat
{
[Activity(Label = "粮情检测结果")]
public class InCludeGrainResult : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.InCludeGrainResult);
Android.Graphics.Color tvcolorMax;
Android.Graphics.Color tvcolorMin;
Android.Graphics.Color tvcolorAvg;
Android.Graphics.Color tvcolorNormal;
tvcolorMax = new Android.Graphics.Color(255, 0, 0);
tvcolorMin = new Android.Graphics.Color(0, 255, 0);
tvcolorAvg = new Android.Graphics.Color(0, 0, 255);
tvcolorNormal = new Android.Graphics.Color(255, 255, 255);
ISharedPreferences preMy = GetSharedPreferences("Settings", 0); //获取内部存储中currStore中存储的当前仓房信息
string strcurrStore = preMy.GetString("currStore", "");
string[] LocalStoreArgs;
LocalStoreArgs = strcurrStore.Split("|");
int iHeight = int.Parse(LocalStoreArgs[1]);
int iWidth = int.Parse(LocalStoreArgs[2]);
int iStartCableNum = int.Parse(LocalStoreArgs[3]);
int iEndCableNum = int.Parse(LocalStoreArgs[4]);
GridLayout gl = FindViewById<GridLayout>(Resource.Id.GL);
gl.RowCount = iHeight * iWidth + iWidth - 1; //根据变量设置行数
gl.ColumnCount = (iEndCableNum - iStartCableNum + 1) / iWidth; //根据变量设置列数
Intent intent = this.Intent; //获取主窗口单击粮情菜单后推送到本窗口的结果
string strSky = intent.GetStringExtra("strSky");
string[] arrStrSky;
arrStrSky = strSky.Split(" ");
TextView tvSkyTemp = FindViewById<TextView>(Resource.Id.textviewSkyTemp);
TextView tvSkyHudi = FindViewById<TextView>(Resource.Id.textviewSkyHudi);
tvSkyTemp.Text = arrStrSky[0];
tvSkyHudi.Text = arrStrSky[1];
string strStore = intent.GetStringExtra("strStore");
string[] arrStrStore;
arrStrStore = strStore.Split(" ");
TextView tvStoreTemp = FindViewById<TextView>(Resource.Id.textviewStoreTemp);
TextView tvStoreHudi = FindViewById<TextView>(Resource.Id.textviewStoreHudi);
tvStoreTemp.Text = arrStrStore[0];
tvStoreHudi.Text = arrStrStore[1];
string strGrainMMA = intent.GetStringExtra("strGrainMMA");
string[] arrGrainMMA;
arrGrainMMA = strGrainMMA.Split(" ");
TextView tvMaxTemp = FindViewById<TextView>(Resource.Id.textviewMaxTemp);
TextView tvMinTemp = FindViewById<TextView>(Resource.Id.textviewMinTemp);
TextView tvAvgTemp = FindViewById<TextView>(Resource.Id.textviewAvgTemp);
tvMaxTemp.Text = arrGrainMMA[0];
tvMaxTemp.SetTextColor(tvcolorMax);
tvMinTemp.Text = arrGrainMMA[1];
tvMinTemp.SetTextColor(tvcolorMin);
tvAvgTemp.Text = arrGrainMMA[2];
tvAvgTemp.SetTextColor(tvcolorAvg);
string strGrain = intent.GetStringExtra("strGrain");
string[] arrStrGrain;
arrStrGrain = strGrain.Split("|"); //全部数据 arrStrGrain 的内容为12.3|11.0|13.2....
for (int i = 0; i < arrStrGrain.Length; i++) //重点 创建显示数据
{
TextView tv = new TextView(this);
tv.Text = arrStrGrain[i].ToString().PadLeft(10);
string strTmp = "";
strTmp = tv.Text.Trim();
if (strTmp == tvMaxTemp.Text)
{
tv.SetTextColor(tvcolorMax);
}
else if (strTmp == tvMinTemp.Text)
{
tv.SetTextColor(tvcolorMin);
}
else if (strTmp == tvAvgTemp.Text)
{
tv.SetTextColor(tvcolorAvg);
}
else
{
tv.SetTextColor(tvcolorNormal);
}
gl.AddView(tv, i);
}
}
}
因为使用了两种滚动视图,所以可以上下左右拖动查看大量数据