学习记录:Visual Studio 2019中使用C#进行Android开发08 用ScrollView HorizontalScrollView GridLayout实现大量数据的行列显示

两个布局文件

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

            }
        }

     

       
}

因为使用了两种滚动视图,所以可以上下左右拖动查看大量数据

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iamtsfw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值