Android 生成颜色器
<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="vertical" > <LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="请输入行:"
/> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal" /> </LinearLayout> <LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="请输入列:"
/> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal"> <requestFocus />
</EditText> </LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="一键自动生成表格"
/> </LinearLayout> </LinearLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/table1"> </TableLayout> </LinearLayout>
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity {
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int MP = ViewGroup.LayoutParams.MATCH_PARENT;
private EditText row;
private EditText column;
private Button bt1;
private TableLayout tableLayout; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取控件Button
bt1=(Button) findViewById(R.id.button1);
//获取文本输入框控件
row=(EditText) findViewById(R.id.editText1);
column=(EditText) findViewById(R.id.editText2); //给button按钮绑定单击事件
bt1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
//Color[] colorBlocks= new Color[4096];
//int row_int=Integer.parseInt(row.getText().toString());
//int col_int=Integer.parseInt(column.getText().toString()); //获取控件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);
//Button bt=new Button(MainActivity.this); tv.setText("-");
tv.setBackgroundColor( Color.rgb(red*16, green*16, blue*16) ); //Color.rgb(red*16-1, green*16-1, blue*16-1)
//tv.setBackgroundResource(35434);
tableRow.addView(tv);
}
//新建的TableRow添加到TableLayout tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));
} }
}); } }
效果呢,博客就不展示了。可以自己试试。黄沙百战穿金甲,不破楼兰终不还
Android 生成颜色器的更多相关文章
- android_demo之生成颜色布局
前面学习了动态生成表格,不单单是要动态生成控件,也同时生成一个事件. 接下来用个小小栗子去了解这个知识点. <LinearLayout xmlns:android="http://sc ...
- android 资讯阅读器
最近找申请到了一个不错的接口 , 非常适合拿来写一个资讯类的app. 现在着手写,随写随更.也算是抛砖引玉.烂尾请勿喷.╭(╯^╰)╮ android 资讯阅读器 第一阶段目标样式(滑动切换标签 , ...
- Android生成二维码--拍照或从相册选取图片
拍照或从相册选择图片是我们日常开发中经常使用到的,可以说是必须掌握的东西.上一篇我介绍了如何生成自定义二维码<Android生成自定义二维码>,其中logo和代替黑色色块的图片都是写死的, ...
- Android VLC播放器二次开发3——音乐播放(歌曲列表+歌词同步滚动)
今天讲一下对VLC播放器音频播放功能进行二次开发,讲解如何改造音乐播放相关功能.最近一直在忙着优化视频解码部分代码,因为我的视频播放器需要在一台主频比较低的机器上跑(800M主频),所以视频解码能力受 ...
- Android VLC播放器二次开发2——CPU类型检查+界面初始化
上一篇讲了VLC整个程序的模块划分和界面主要使用的技术,今天分析一下VLC程序初始化过程,主要是初始化界面.加载解码库的操作.今天主要分析一下org.videolan.vlc.gui.MainActi ...
- Android 图片压缩器
概述 Android 图片压缩器:一款高效的图片压缩器库,支持批量压缩,异步压缩.多线程多任务压缩,压缩比设置等特性. 详细 代码下载:http://www.demodashi.com/demo/12 ...
- Android布局管理器-使用FrameLayout帧布局管理器显示层叠的正方形以及前景照片
场景 Android布局管理器-使用LinearLayout实现简单的登录窗口布局: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...
- Android布局管理器-使用LinearLayout实现简单的登录窗口布局
场景 Android布局管理器-从实例入手学习相对布局管理器的使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1038389 ...
- Android音乐播放器源码(歌词.均衡器.收藏.qq5.0菜单.通知)
一款Android音乐播放器源码,基本功能都实现了 qq5.0菜单(歌词.均衡器.收藏.qq5.0菜单.通知) 只有向右滑动出现,菜单键和指定按钮都还没有添加. 源码下载:http://code.66 ...
随机推荐
- 02-FPGA设计流程介绍——小梅哥FPGA设计思想与验证方法视频教程配套文档
芯航线——普利斯队长精心奉献 课程目标: 1.了解并学会FPGA开发设计的整体流程 2.设计一个二选一选择器并进行功能仿真.时序仿真以及板级验证 实验平台:芯航线FPGA开发板.杜邦线 实验内容: 良 ...
- 如何使用VS2013对C++进行编程
https://msdn.microsoft.com/zh-cn/library/bb384842.aspx
- python 注意事项
常见错误 #4: 不理解Python的作用域 Python是基于 LEGB 来进行作用于解析的, LEGB 是 Local, Enclosing, Global, Built-in 的缩写.看起来“ ...
- [问题2015S13] 复旦高等代数 II(14级)每周一题(第十四教学周)
[问题2015S13] 设 \(A=(a_{ij})\) 为 \(n\) 阶实矩阵, 定义函数 \[f(A)=\sum_{i,j=1}^na_{ij}^2.\] 设 \(P\) 为 \(n\) 阶非 ...
- Java中ExecutorService和CompletionService区别
我们现在在Java中使用多线程通常不会直接用Thread对象了,而是会用到java.util.concurrent包下的ExecutorService类来初始化一个线程池供我们使用. 之前我一直习惯自 ...
- svn查看代码作者的命令
svn blame **.java | grep ** svn查看代码作者的命令
- django"动态网页","动态url","调试方法"
一.动态网页 其实只是每次刷新时,获取最新时间而已 1.urls.py from django.conf.urls import patterns, url, include urlpatterns ...
- Oracle新增客户端网络配置使用scott出现错误
错误一 测试提示用户密码过期 解决方法:使用sys用户登录数据库 sqlplus sys/密码 as sysdba; 修改scott用户密码 alter user scott identifie ...
- 在腾讯云上创建您的SQL Cluster(4)
版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/255 来源:腾云阁 https://www.qclo ...
- python爬虫(1)
了解python的基本语法后就可以开始了,边学边巩固. 学爬虫那什么是网络爬虫,以下是百度百科的定义:网络爬虫(又被称为网页蜘蛛,网络机器人, 在FOAF社区中间,更经常的称为网页追逐者),是一种按照 ...