首页 技术 正文
技术 2022年11月17日
0 收藏 342 点赞 4,237 浏览 2772 个字

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

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

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

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

android_demo  之生成颜色

/DynamicTable/res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="一键自动生成" />
</LinearLayout> <TableLayout
android:id="@+id/table1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout></LinearLayout>

activity_main.xml

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

package com.example.dynamictable;import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;public class MainActivity extends Activity {
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int MP = ViewGroup.LayoutParams.MATCH_PARENT;
private Button bt1;
private TableLayout tableLayout;
private int c; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取控件Button
bt1 = (Button) findViewById(R.id.button1); // 给button按钮绑定单击事件
bt1.setOnClickListener(new OnClickListener() { public void onClick(View v) {
// 获取控件tableLayout
tableLayout = (TableLayout) findViewById(R.id.table1);
// 清除表格所有行
tableLayout.removeAllViews();
// 全部列自动填充空白处
tableLayout.setStretchAllColumns(true);
// 生成X行,Y列的表格 int theLength = 64;
for (int i = 0; i < theLength; i++) {
TableRow tableRow = new TableRow(MainActivity.this);
for (int j = 0; j < theLength; j++) {
int result = i * theLength + (j + 1) - 1;// 0~4095
int red = result / 256;
int green = (result - red * 256) / 16;
int blue = result - red * 256 - green * 16; // tv用于显示
TextView tv = new TextView(MainActivity.this); // tv.setText("-");
int rgb = Color.rgb(red * 16, green * 16, blue * 16);
tv.setBackgroundColor(rgb); // Color.rgb(red*16-1, green*16-1, blue*16-1)
// tv.setBackgroundResource(35434);
tableRow.addView(tv);
// System.out.println("i="+i+"; j="+j);
System.out.println(rgb + "=" + c++);
}
// 新建的TableRow添加到TableLayout
tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC, 1));
}
}
});
}
}

MainActivity.java

-_-|||

这就是代码了  (o_ _)ノ

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

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

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

展示展示效果

android_demo  之生成颜色

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

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

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

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

android_demo  之生成颜色

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

搜图片有这样的

android_demo  之生成颜色

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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905