老师说循环出颜色数字  然后显示出来

他说的什么一脸懵逼(=@__@=)   代码还在手上也还是懵逼 (づ。◕‿‿◕。)づ

不管了   留个脚印在这 以后想起来   至少也知道

直接上代码吧    说再多我也不懂啊(¬_¬)

/DynamicTable/res/layout/activity_main.xml

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <LinearLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:orientation="horizontal" >
  11.  
  12. <Button
  13. android:id="@+id/button1"
  14. android:layout_width="match_parent"
  15. android:layout_height="wrap_content"
  16. android:text="一键自动生成" />
  17. </LinearLayout>
  18.  
  19. <TableLayout
  20. android:id="@+id/table1"
  21. android:layout_width="match_parent"
  22. android:layout_height="match_parent" >
  23. </TableLayout>
  24.  
  25. </LinearLayout>

activity_main.xml

/DynamicTable/src/com/example/dynamictable/MainActivity.java

  1. package com.example.dynamictable;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Color;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.view.ViewGroup;
  9. import android.widget.Button;
  10. import android.widget.TableLayout;
  11. import android.widget.TableRow;
  12. import android.widget.TextView;
  13.  
  14. public class MainActivity extends Activity {
  15. private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
  16. private final int MP = ViewGroup.LayoutParams.MATCH_PARENT;
  17. private Button bt1;
  18. private TableLayout tableLayout;
  19. private int c;
  20.  
  21. protected void onCreate(Bundle savedInstanceState) {
  22.  
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. // 获取控件Button
  26. bt1 = (Button) findViewById(R.id.button1);
  27.  
  28. // 给button按钮绑定单击事件
  29. bt1.setOnClickListener(new OnClickListener() {
  30.  
  31. public void onClick(View v) {
  32. // 获取控件tableLayout
  33. tableLayout = (TableLayout) findViewById(R.id.table1);
  34. // 清除表格所有行
  35. tableLayout.removeAllViews();
  36. // 全部列自动填充空白处
  37. tableLayout.setStretchAllColumns(true);
  38. // 生成X行,Y列的表格
  39.  
  40. int theLength = 64;
  41. for (int i = 0; i < theLength; i++) {
  42. TableRow tableRow = new TableRow(MainActivity.this);
  43. for (int j = 0; j < theLength; j++) {
  44. int result = i * theLength + (j + 1) - 1;// 0~4095
  45. int red = result / 256;
  46. int green = (result - red * 256) / 16;
  47. int blue = result - red * 256 - green * 16;
  48.  
  49. // tv用于显示
  50. TextView tv = new TextView(MainActivity.this);
  51.  
  52. // tv.setText("-");
  53. int rgb = Color.rgb(red * 16, green * 16, blue * 16);
  54. tv.setBackgroundColor(rgb);
  55.  
  56. // Color.rgb(red*16-1, green*16-1, blue*16-1)
  57. // tv.setBackgroundResource(35434);
  58. tableRow.addView(tv);
  59. // System.out.println("i="+i+"; j="+j);
  60. System.out.println(rgb + "=" + c++);
  61. }
  62. // 新建的TableRow添加到TableLayout
  63. tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC, 1));
  64. }
  65. }
  66. });
  67. }
  68. }

MainActivity.java

-_-|||

这就是代码了  (o_ _)ノ

注意运行的时候会比较慢,当你一直看见那个页面不动,不要激动,请耐心等待,好事多磨。你懂的。

由于考虑到电脑的因素我们就不循环全部颜色出来,只取其中的一部分。看见上面的颜色表,只是一部分而已,

这是16的   就是  那个  int theLength = 64;

展示展示效果

那什么  255什么的还是不敢试

测试了一半就强制退出了  囧rz=З  怕啊┑( ̄Д  ̄)┍   怕手机hold 不住啊。

那什么 我还是瞎测试了一下 32的 就是   int theLength = 128; 的

等了好久才出了╮(╯_╰)╭

反正感觉它(ーー゛)好(@ ̄ー ̄@)丑

搜图片有这样的

感觉都要比那个循环出来的好看o( ̄ヘ ̄o#)

这手机截屏怎么这么大啊   崩溃(# ̄~ ̄#)

android_demo 之生成颜色的更多相关文章

  1. android_demo之生成颜色布局

    前面学习了动态生成表格,不单单是要动态生成控件,也同时生成一个事件. 接下来用个小小栗子去了解这个知识点. <LinearLayout xmlns:android="http://sc ...

  2. Android 生成颜色器

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  3. JavaScript随机生成颜色以及十六进制颜色 与RGB颜色值的相互转换

    /** * 随机生成颜色 * @return 随机生成的十六进制颜色 */ function randomColor(){ var colorStr=Math.floor(Math.random()* ...

  4. iOS -UIColor随机生成颜色的方法

    在iOS 中的UIColor拥有这么多关于颜色的类方法,对于一般常见的UI控件,我们可以通过[UIColorblackColor]设置背景色 eg:设置button 的背景色为红色 UIButton ...

  5. Android_demo之生成二维码

    今天我们来学习一个自动生成二维码 的写法.我们经常能见到各种二维码,比如公众号的二维码,网址的,加好友的,支付的二维码等等.其实每一个二维码只是利用图片的形式展示出来的,实际是一些字符串.而这个字符串 ...

  6. js随机生成颜色代码

    function generyRandomColor() { return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toStri ...

  7. js随机生成颜色的方法

    function getRandomColor() { return '#' + (Math.random() * 0xffffff << 0).toString(16); }

  8. js 随机生成颜色

    方法一  function randomColor (){ var str='#'; for(var i=0;i<6;i++){ str+=Math.floor(Math.random()*16 ...

  9. .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度

    .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度   随机颜色在日常开发中很常用到,有时候要控制颜色明亮度,比如在白色背景网页上的随机颜色,一般要求颜色稍微暗一 ...

随机推荐

  1. 格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  2. 配置Windows 2008 R2 防火墙允许远程访问SQL Server 2008 R2 更改端口 连接字符串 IP+逗号+端口号

      1.先修改 sql server 2008R2的端口号吧,1433经常成为别人入侵的端口,在sql server 配置管理器 -->sql server 网络配置-->MSSQLSER ...

  3. 黑魔法__attribute__((cleanup))

    原文地址:http://blog.sunnyxx.com/2014/09/15/objc-attribute-cleanup/ 编译器属性__attribute__用于向编译器描述特殊的标识.检查或优 ...

  4. IOS调试lldb命令常用po

    lldb命令常用(备忘) 假如你准备在模拟器里面运行这个,你可以在“(lldb)”提示的后面输入下面的: (lldb) po $eax LLDB在xcode4.3或者之后的版本里面是默认的调试器.假如 ...

  5. oracle查询和断开用户session

    select sid,serial#,username from v$session where username='user_name';alter system kill session 'sid ...

  6. QFII

    QFII(Qualified Foreign Institutional Investors)合格的境外机构投资者的英文简称,中文“酋匪”,QFII机制是指外国专业投资机构到境内投资的资格认定制度. ...

  7. SpriteKit所有的类

    1.SKAction 2.SKCropNode 3.SKEffectNode 4.SKEmitterNode 5.SKKeyframeSequence 6.SKLabelNode 7.SKNode 8 ...

  8. codeforces 148D之概率DP

    http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory l ...

  9. App发布AppStore【苹果开发者中心需要做的事】

    请准许我的这句抱怨,也说明发布app到AppStore理清这些东西的重要性:起初打包出现各种 ApplicationVerificationFailed,不是这里没有搞对就是那个证书没有搞对,整个人签 ...

  10. cas 官方文档

    1. 架构 http://jasig.github.io/cas/4.0.0/planning/Architecture.html System Components The CAS server a ...