Silverlight日记:动态生成DataGrid、行列装换、动态加载控件

本文主要针对使用DataGrid动态绑定数据对象,并实现行列转换效果。

一,前台绑定

<sdk:DataGrid x:Name="dataGrid2" Style="{StaticResource ResourceKey=safeDataGrid2}" />
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Test.Util;

namespace Test
{
    public partial class MainPage : UserControl
    {
        public Md Model = null;
        private DispatcherTimer timer;
        int index = 0;
        /// <summary>
        ///
        /// </summary>
        public ObservableCollection<Obj> objs = new ObservableCollection<Obj>();

        public MainPage()
        {
            InitializeComponent();
            init();
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 8);
            timer.Tick += timer_Tick;
            timer.Start();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void timer_Tick(object sender, EventArgs e)
        {
            var ramd = new Random();
            foreach (var tag in Model.Tags)
            {
                foreach (var para in Consts.Params)
                {
                    var rv = index % 2 == 0 ? ramd.Next(2, 10) : ramd.Next(1, 5);
                    var o = new Obj
                    {
                        IsAlarm = false,
                        Value = (0.5 + rv).ToString(),
                        State = index % 2 == 0 ? 1 : 0,
                        MeterId = tag.F_METER_ID,
                        MeterName = tag.F_METER_NAME,
                        ParaId = para.Id
                    };
                    if (para.Id == "10")
                    {
                        o.IsAlarm = false;
                        o.ParaId = string.Empty;
                        o.State = 0;
                        o.Value = string.Empty;
                    }
                    var temp = objs.FirstOrDefault(i => i.MeterName.Equals(o.MeterName) && i.ParaId == o.ParaId);
                    if (temp != null)
                    {
                        temp.IsAlarm = o.IsAlarm;
                        temp.State = o.State;
                        temp.Value = o.Value;
                    }
                    else
                        objs.Add(o);
                }
            }
            //CommHelper.GetSource(Model.Tags, objs, ref this.dataGrid2);
            CommHelper.BindData(Model.Tags, objs, ref this.dataGrid2);
            index++;
        }

        /// <summary>
        ///
        /// </summary>
        void init()
        {
            Model = new Md();
            Model.Tags = new List<T_METER>();
            Model.Eles = new List<Param>();
            for (int i = 0; i < 1; i++)
            {
                var temp = new T_METER
                {
                    F_BUILD_ID = "440300B059",
                    F_METER_ID = string.Format("TAG_{0}", i),
                    F_METER_NAME = string.Format("CM-{0}", i)
                };
                if (i == 0)
                    temp.F_EQT_TYPE = "D";
                else if (i == 1)
                    temp.F_EQT_TYPE = "C";
                else if (i == 2)
                    temp.F_EQT_TYPE = "E";
                else
                    temp.F_EQT_TYPE = "A";
                Model.Tags.Add(temp);
            }
            this.dataGrid1.ItemsSource = Consts.Params;
            CommHelper.CreateDataGrid(Model.Tags, ref this.dataGrid2);
        }
    }

    /// <summary>
    ///
    /// </summary>
    public class Md
    {
        /// <summary>
        /// 参数集合
        /// </summary>
        public List<Param> Eles { get; set; }
        /// <summary>
        /// 电表集合
        /// </summary>
        public List<T_METER> Tags { get; set; }
    }
    /// <summary>
    ///
    /// </summary>
    public class T_METER
    {
        public string F_BUILD_ID { get; set; }
        public string F_METER_ID { get; set; }

        public string F_METER_NAME { get; set; }

        public string F_EQT_TYPE { get; set; }

        public string F_VALUE { get; set; }
    }

    /// <summary>
    /// 参数
    /// </summary>
    public class Param
    {
        public string Id { get; set; }

        public string Name { get; set; }
    }

    /// <summary>
    /// 绑定数据对象
    /// </summary>
    public class Obj
    {
        /// <summary>
        /// 对应参数编号
        /// </summary>
        public string ParaId { get; set; }

        public string MeterId { get; set; }
        /// <summary>
        /// 电表名称
        /// </summary>
        public string MeterName { get; set; }
        /// <summary>
        /// 开关状态0-关,1-开
        /// </summary>
        public int State { get; set; }
        /// <summary>
        /// OPC读取值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 是否报警
        /// </summary>
        public bool IsAlarm { get; set; }

    }

}

  

二,动态列对象

 1 using System.Collections.Generic;
 2
 3 namespace Test.Util
 4 {
 5     /* ==============================
 6      * Desc:DynamicColumn
 7      * Author:hezp
 8      * Date:2014/8/14 15:49:17
 9      * ==============================*/
10     public class DynamicColumn
11     {
12         /// <summary>
13         /// 列名
14         /// </summary>
15         public string ColumnName { get; set; }
16         /// <summary>
17         /// 列对应集合
18         /// </summary>
19         public List<string> Values { get; set; }
20     }
21 }

三,DataGrid动态生成类

  1 using System;
  2 using System.Linq;
  3 using System.Collections;
  4 using System.Collections.Generic;
  5 using System.Net;
  6 using System.Text;
  7 using System.Windows;
  8 using System.Windows.Controls;
  9 using System.Windows.Documents;
 10 using System.Windows.Ink;
 11 using System.Windows.Input;
 12 using System.Windows.Markup;
 13 using System.Windows.Media;
 14 using System.Windows.Media.Animation;
 15 using System.Windows.Shapes;
 16 using System.Text.RegularExpressions;
 17 using System.Collections.ObjectModel;
 18
 19 namespace Test.Util
 20 {
 21     /* ==============================
 22      * Desc:CommHelper
 23      * Author:hezp
 24      * Date:2014/8/14 15:58:26
 25      * ==============================*/
 26     public class CommHelper
 27     {
 28         /// <summary>
 29         ///
 30         /// </summary>
 31         /// <param name="columnBindName"></param>
 32         /// <param name="columnHeaderName"></param>
 33         /// <param name="width"></param>
 34         /// <param name="index"></param>
 35         /// <returns></returns>
 36         private static DataGridTemplateColumn CreateDataGridTextColumn(string columnBindName, string columnHeaderName, T_METER tag)
 37         {
 38             DataGridTemplateColumn dgColumn = new DataGridTemplateColumn();
 39             dgColumn.Header = columnHeaderName;
 40             dgColumn.IsReadOnly = true;
 41             var w = 70;
 42             if (tag != null)
 43             {
 44                 if (tag.F_EQT_TYPE.Equals("D"))
 45                 {
 46                     dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeByqStyle");
 47                     w = 120;
 48                 }
 49                 else if (tag.F_EQT_TYPE.Equals("B"))
 50                 {
 51                     dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeSingleDrStyle");
 52                     w = 90;
 53                 }
 54                 else if (tag.F_EQT_TYPE.Equals("C"))
 55                 {
 56                     dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeDoubleDrStyle");
 57                     w = 150;
 58                 }
 59                 else if (tag.F_EQT_TYPE.Equals("E"))
 60                 {
 61                     dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeHookStyle");
 62                     w = 98;
 63                 }
 64                 else
 65                     dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeMeterStyle");
 66             }
 67             else
 68                 dgColumn.HeaderStyle = ResourcesWrapper.GetStyle<Style>("safeMeterStyle");
 69
 70             dgColumn.CellStyle = ResourcesWrapper.GetStyle<Style>("safeCellStyle");
 71
 72             StringBuilder cellTemplate = new StringBuilder();
 73             cellTemplate.Append("<DataTemplate  ");
 74             cellTemplate.Append(" xmlns=‘http://schemas.microsoft.com/client/2007‘ ");
 75             cellTemplate.Append(" xmlns:x=‘http://schemas.microsoft.com/winfx/2006/xaml‘ ");
 76             cellTemplate.Append(" xmlns:c=‘clr-namespace:Test.Controls;assembly=Test.Controls‘ ");
 77             cellTemplate.Append(" xmlns:local = ‘Test");
 78             cellTemplate.Append(";assembly=Test‘>");
 79             cellTemplate.Append(string.Format("<c:CustomCell Width=‘{1}‘ Text=‘{{Binding {0}}}‘/>", columnBindName, w));
 80             cellTemplate.Append("</DataTemplate>");
 81             dgColumn.CellTemplate = (DataTemplate)XamlReader.Load(cellTemplate.ToString());
 82             dgColumn.CellTemplate.LoadContent();
 83
 84             return dgColumn;
 85         }
 86
 87         /// <summary>
 88         ///
 89         /// </summary>
 90         /// <param name="SourceList"></param>
 91         /// <returns></returns>
 92         private static IEnumerable<IDictionary> GetEnumerable(List<Dictionary<string, string>> SourceList)
 93         {
 94             for (int i = 0; i < SourceList.Count; i++)
 95             {
 96                 var dict = new Dictionary<string, string>();
 97                 dict = SourceList[i];
 98                 yield return dict;
 99             }
100         }
101         /// <summary>
102         ///
103         /// </summary>
104         /// <param name="list"></param>
105         /// <param name="objs"></param>
106         /// <returns></returns>
107         private static List<DynamicColumn> Grenartor(List<T_METER> list, ObservableCollection<Obj> objs)
108         {
109             var columns = new List<DynamicColumn>();
110             if (null == list) return null;
111             var ms = from p in list
112                      group p by new { p.F_BUILD_ID, p.F_METER_ID, p.F_METER_NAME } into gg
113                      select gg.Key;
114             var ramd = new System.Random();
115             foreach (var m in ms)
116             {
117                 var column = new DynamicColumn
118                 {
119                     ColumnName = string.Format("{0}____{1}", m.F_METER_NAME, 0)//格式:支路名称|开关状态值
120                 };
121                 if (objs != null)
122                 {
123                     var obj = objs.FirstOrDefault(i => i.MeterName.Equals(m.F_METER_NAME));
124                     if (obj != null)
125                         column.ColumnName = string.Format("{0}____{1}", obj.MeterName, obj.State);
126                 }
127                 column.Values = new List<string>();
128                 var count = Consts.Params.Count;
129                 for (int i = 0; i < count; i++)
130                 {
131                     var v = false;//是否显示按钮
132                     if (i == count - 1)
133                         v = true;
134                     if (objs != null)
135                     {
136                         var temp = objs.FirstOrDefault(j => j.MeterName.Equals(m.F_METER_NAME) && !string.IsNullOrEmpty(j.ParaId) && j.ParaId.Equals(Consts.Params[i].Id));
137                         if (temp != null)
138                             column.Values.Add(string.Format("{0}____{1}____{2}____{3}____{4}____{5}____{6}", m.F_BUILD_ID, m.F_METER_ID, m.F_METER_NAME, temp.Value, v, temp.IsAlarm, Consts.Params[i].Id));
139                         else
140                             column.Values.Add(string.Format("{0}____{1}____{2}____{3}____{4}____{5}____{6}", m.F_BUILD_ID, m.F_METER_ID, m.F_METER_NAME, "-", v, false, Consts.Params[i].Id));//格式:建筑编号____支路编号____支路名称____数值____是否是按钮____是否报警
141                     }
142                     else
143                         column.Values.Add(string.Format("{0}____{1}____{2}____{3}____{4}____{5}____{6}", m.F_BUILD_ID, m.F_METER_ID, m.F_METER_NAME, "-", v, false, Consts.Params[i].Id));
144                 }
145                 columns.Add(column);
146             }
147             return columns;
148         }
149         /// <summary>
150         /// 绑定数据
151         /// </summary>
152         /// <param name="tags"></param>
153         /// <param name="objs"></param>
154         /// <param name="datagrid"></param>
155         public static void BindData(List<T_METER> tags, ObservableCollection<Obj> objs, ref DataGrid datagrid)
156         {
157             var list = Grenartor(tags, objs);
158             var dataSources = new List<Dictionary<string, string>>();
159             for (int j = 0; j < 10; j++)
160             {
161                 var dict = new Dictionary<string, string>();//数据行(Key:列名,Value:列值)
162                 list.ForEach(item =>
163                 {
164                     dict.Add(item.ColumnName.Replace(" ", "_").Replace("-", "_"), item.Values[j]);
165                 });
166                 dataSources.Add(dict);
167             }
168             foreach (var item in list)
169             {
170                 var index = list.IndexOf(item);
171                 var arr = Regex.Split(item.ColumnName, "____", RegexOptions.IgnoreCase);
172                 var tag = tags.FirstOrDefault(i => i.F_METER_NAME.ToUpper().Equals(arr[0].ToUpper()));
173                 var column = CreateDataGridTextColumn(item.ColumnName.Replace(" ", "_").Replace("-", "_"), item.ColumnName, tag);
174                 var cl = datagrid.Columns.FirstOrDefault(i => i.Header.ToString().StartsWith(tag.F_METER_NAME));
175                 if (cl != null)
176                     cl = column;
177                 else
178                     datagrid.Columns.Add(column);
179             }
180             datagrid.ItemsSource = GetEnumerable(dataSources).ToDataSource();
181         }
182
183         public static void GetSource(List<T_METER> tags, ObservableCollection<Obj> objs, ref DataGrid datagrid)
184         {
185             var list = Grenartor(tags, objs);
186             var dataSources = new List<Dictionary<string, string>>();
187             for (int j = 0; j < 10; j++)
188             {
189                 var dict = new Dictionary<string, string>();//数据行(Key:列名,Value:列值)
190                 list.ForEach(item =>
191                 {
192                     dict.Add(item.ColumnName.Replace(" ", "_").Replace("-", "_"), item.Values[j]);
193                 });
194                 dataSources.Add(dict);
195             }
196             datagrid.ItemsSource = GetEnumerable(dataSources).ToDataSource();
197         }
198
199         public static void CreateDataGrid(List<T_METER> tags, ref DataGrid datagrid)
200         {
201             var list = Grenartor(tags, null);
202             var dataSources = new List<Dictionary<string, string>>();
203             for (int j = 0; j < 10; j++)
204             {
205                 var dict = new Dictionary<string, string>();//数据行(Key:列名,Value:列值)
206                 list.ForEach(item =>
207                 {
208                     dict.Add(item.ColumnName.Replace(" ", "_").Replace("-", "_"), item.Values[j]);
209                 });
210                 dataSources.Add(dict);
211             }
212             foreach (var item in list)
213             {
214                 var index = list.IndexOf(item);
215                 var arr = Regex.Split(item.ColumnName, "____", RegexOptions.IgnoreCase);
216                 var tag = tags.FirstOrDefault(i => i.F_METER_ID.ToUpper().Equals(arr[0].ToUpper()));
217                 var column = CreateDataGridTextColumn(item.ColumnName.Replace(" ", "_").Replace("-", "_"), item.ColumnName, tag);
218                 var cl = datagrid.Columns.FirstOrDefault(i => i.Header.ToString().StartsWith(tag.F_METER_NAME));
219                 if (cl != null)
220                     cl = column;
221                 else
222                     datagrid.Columns.Add(column);
223             }
224             datagrid.ItemsSource = GetEnumerable(dataSources).ToDataSource();
225         }
226     }
227 }

四,数据源构造(实现行列转换)类

  1 using System;
  2 using System.Collections;
  3 using System.Collections.Generic;
  4 using System.Collections.ObjectModel;
  5 using System.Reflection;
  6 using System.Reflection.Emit;
  7
  8 namespace Test.Util
  9 {
 10     /* ==============================
 11      * Desc:DataSourceCreator
 12      * Author:hezp
 13      * Date:2014/8/14 15:51:04
 14      * ==============================*/
 15     public static class DataSourceCreator
 16     {
 17         public static ObservableCollection<object> ToDataSource(this IEnumerable<IDictionary> list)
 18         {
 19             IDictionary firstDict = null;
 20             bool hasData = false;
 21             foreach (IDictionary currentDict in list)
 22             {
 23                 hasData = true;
 24                 firstDict = currentDict;
 25                 break;
 26             }
 27             if (!hasData)
 28             {
 29                 return new ObservableCollection<object> { };
 30             }
 31             if (firstDict == null)
 32             {
 33                 throw new ArgumentException("IDictionary entry cannot be null");
 34             }
 35             Type objectType = null;
 36             TypeBuilder tb = GetTypeBuilder(list.GetHashCode());
 37             ConstructorBuilder constructor =
 38                         tb.DefineDefaultConstructor(
 39                                     MethodAttributes.Public |
 40                                     MethodAttributes.SpecialName |
 41                                     MethodAttributes.RTSpecialName);
 42             foreach (DictionaryEntry pair in firstDict)
 43             {
 44
 45                 CreateProperty(tb,
 46                                 Convert.ToString(pair.Key),
 47                                 pair.Value == null ?
 48                                             typeof(object) :
 49                                             pair.Value.GetType());
 50
 51             }
 52             objectType = tb.CreateType();
 53             return GenerateArray(objectType, list, firstDict);
 54         }
 55         private static ObservableCollection<object> GenerateArray(Type objectType, IEnumerable<IDictionary> list, IDictionary firstDict)
 56         {
 57             var itemsSource = new ObservableCollection<object>();
 58             foreach (var currentDict in list)
 59             {
 60                 object row = Activator.CreateInstance(objectType);
 61                 foreach (DictionaryEntry pair in firstDict)
 62                 {
 63                     if (currentDict.Contains(pair.Key))
 64                     {
 65                         PropertyInfo property =
 66                             objectType.GetProperty(Convert.ToString(pair.Key));
 67                         property.SetValue(
 68                             row,
 69                             Convert.ChangeType(
 70                                     currentDict[pair.Key],
 71                                     property.PropertyType,
 72                                     null),
 73                             null);
 74                     }
 75                 }
 76                 itemsSource.Add(row);
 77             }
 78             return itemsSource;
 79         }
 80         private static TypeBuilder GetTypeBuilder(int code)
 81         {
 82             AssemblyName an = new AssemblyName("TempAssembly" + code);
 83             AssemblyBuilder assemblyBuilder =
 84                 AppDomain.CurrentDomain.DefineDynamicAssembly(
 85                     an, AssemblyBuilderAccess.Run);
 86             ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule");
 87             TypeBuilder tb = moduleBuilder.DefineType("TempType" + code
 88                                 , TypeAttributes.Public |
 89                                 TypeAttributes.Class |
 90                                 TypeAttributes.AutoClass |
 91                                 TypeAttributes.AnsiClass |
 92                                 TypeAttributes.BeforeFieldInit |
 93                                 TypeAttributes.AutoLayout
 94                                 , typeof(object));
 95             return tb;
 96         }
 97         private static void CreateProperty(TypeBuilder tb, string propertyName, Type propertyType)
 98         {
 99             FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName,
100                                                         propertyType,
101                                                         FieldAttributes.Private);
102
103             PropertyBuilder propertyBuilder =
104                 tb.DefineProperty(
105                     propertyName, PropertyAttributes.HasDefault, propertyType, null);
106             MethodBuilder getPropMthdBldr =
107                 tb.DefineMethod("get_" + propertyName,
108                     MethodAttributes.Public |
109                     MethodAttributes.SpecialName |
110                     MethodAttributes.HideBySig,
111                     propertyType, Type.EmptyTypes);
112             ILGenerator getIL = getPropMthdBldr.GetILGenerator();
113             getIL.Emit(OpCodes.Ldarg_0);
114             getIL.Emit(OpCodes.Ldfld, fieldBuilder);
115             getIL.Emit(OpCodes.Ret);
116             MethodBuilder setPropMthdBldr =
117                 tb.DefineMethod("set_" + propertyName,
118                   MethodAttributes.Public |
119                   MethodAttributes.SpecialName |
120                   MethodAttributes.HideBySig,
121                   null, new Type[] { propertyType });
122             ILGenerator setIL = setPropMthdBldr.GetILGenerator();
123             setIL.Emit(OpCodes.Ldarg_0);
124             setIL.Emit(OpCodes.Ldarg_1);
125             setIL.Emit(OpCodes.Stfld, fieldBuilder);
126             setIL.Emit(OpCodes.Ret);
127             propertyBuilder.SetGetMethod(getPropMthdBldr);
128             propertyBuilder.SetSetMethod(setPropMthdBldr);
129         }
130     }
131 }

五,显示效果

时间: 2024-10-13 16:29:03

Silverlight日记:动态生成DataGrid、行列装换、动态加载控件的相关文章

解决tableView中cell动态加载控件的重用问题

tableView的cell,有时候需要在运行时取得对应的数据后才能够动态的创建该cell中的控件并加载到该cell中,此时,你一定会遇到重用问题,即使你能做到该cell只根据数值加载了一回控件,你也没法保证不出现重用问题:) 效果(请注意查看,移动下面的格子时,上面出现了重用的问题) 源码: YXCell.h // // YXCell.h // YXTableView // // Copyright (c) 2014年 Y.X. All rights reserved. // #import

[转]如何动态加载控件以及插件编程思想(C#) Zd0

Yann LeCun其人,Facebook AI研究院(FAIR)负责人,深度学习三架马车之一,卷积神经网络(CNN)之父,享受得了万人敬仰,也在无人问津的寒冬挣扎过. 他于1960年出生在巴黎,1987-1989年博士后期间拜在大神Geoffrey Hinton门下,1988年被Larry Jackel招入贝尔实验室,1989年提出在计算机视觉中使用卷积神经网络,其后此项技术被用于在自动取款机上读取支票,影响至今.1998年又提出基于梯度的学习. 或许是天性,又或许是经历过神经网络和深度学习备

js动态加载控件jsp页面

例子1:(具体参照drp中的flow_card_add.jsp)<script>    var rowIndex = 0;     function addOneLineOnClick() {        var row=tblFlowCardDetail.insertRow(tblFlowCardDetail.rows.length);        var col = row.insertCell(0);        col.innerHTML = "<input ty

android 动态背景的实现以及SurfaceView中添加EditText控件

      首先还是一贯作风,我们先看案例: 静态图看不出来效果,如果用过此软件(扎客)的同学们都知道,她的背景会动.怎么样,是不是觉得很时尚,起码比静态的要好(个人观点).其实实现起来并 不复杂,这个如果让做游戏程序员做简直太小儿科了,这里我说明一点,其实我们做应用的也应该多少了解下游戏编程思维,起码对我们做应用有很好的帮助. 下面我简单介绍下实现方式. 实现原理:自定义一个SurfaceView控件.对之不停的onDraw,使得其背景动起来. 对于SurfaceView如果不了解的同学们麻烦

Silverlight系列--动态生成DataGrid列 根据动态列绑定Dictionary数据

1.获取表头数据源动态生成DataGrid表头 DataGridTextColumn d = new DataGridTextColumn(); d.Header = itemPriceClass.PriceKindCode + itemPriceClass.PriceKindName; Binding bin = new Binding(); bin.Converter = new RowIndexConverter(); bin.ConverterParameter = itemPriceC

PHP+Mysql+easyui点击左侧tree菜单对应表名右侧动态生成datagrid加载表单数据(二)

关于tree菜单生成,参考我的另一篇博文地址tree 菜单 实现功能:点击左侧tree菜单中的table,右侧通过datagrid加载出该表对用的所有数据 难点:获取该表的所有列名,动态生成datagrid,并加载数据 解决办法: 使用tree菜单的onClick事件: $('#tree').tree( { url:'tree_getData.php', onClick:function(node){ //判断点击的节点是否是子节点是子节点就创建datagrid,否则就return打开这个节点

CFormView动态调整对话框的尺寸并成比例调整部署控件

基于单文档的CFormView动态调整对话框的尺寸并成比例调整部署控件 如果你正在开发基于单文档程序,使用了CFormView基类实现多个窗口的显示,那么这个文档可能会给你提供些许帮助. 一.实现对话框填充客户区 当我们添加了资源对话框时,它的尺寸在客户区显示时是不会随着窗口的大小调整的,当框架尺寸小于它的尺寸时,还出现了滚动条,操作麻烦同时视觉效果也不良好. 思路 根据客户区的大小调整资源对话框的大小,而客户区大小由父级的框架进行设定. 步骤 1. 根据屏幕分辨率设定框架的尺寸 请注意,我们不

Adroid动态加载Apk-插件化技术框架(动态代理方案)

技术:Android + java +动态加载+插件化 概述 为什么要使用插件化?在开发中,一个项目只会越做越大.初始版本可能是单一功能,后续可能加上各种风马牛不相及的功能.所以我认为插件化可以使得业务分离的更彻底,一人负责哪几个模块,问题也能快速定位.但是也会带来问题:插件和插件之间的交互的复杂性更高.底层支持库因为多个插件需要使用相同的代码可能会变得很大.所以插件化看似解耦了程序员的职责,实际上对于代码质量的要求更高.   实现插件化,最快的方法就是找一个第三方框架.但是要想真正理解,需要真

如何使用SVG生成超酷的页面预加载素描动画效果

在线演示 本地下载 1 SVG简介 可缩放矢量图形是基于可扩展标记语言(标准通用标记语言的子集),用于描述二维矢量图形的一种图形格式.它由万维网联盟制定,是一个开放标准. 2 SVG的特点 与其他图像格式相比(比如 JPEG 和 GIF),使用 SVG 的优势在于: SVG 图像可通过文本编辑器来创建和修改 SVG 图像可被搜索.索引.脚本化或压缩 SVG 是可伸缩的 SVG 图像可在任何的分辨率下被高质量地打印 SVG 可在图像质量不下降的情况下被放大 3 浏览器支持 Internet Exp