首页 文章 精选 留言 我的

精选列表

搜索[布局逻辑],共10003篇文章
优秀的个人博客,低调大师

Android动态布局

每次都忘记,记下来,以后方便查找,代码是从现在的项目中Copy出来的,先来个relativeLayout的 private void setListPath(Context context, RelativeLayout footerRelativeLayout, String ButtonText) { if (flagAddFooterGuide) { // 我的音乐按钮 ImageView myMusic = new ImageView(context); myMusic.setImageResource(R.drawable.style1_mymusic); myMusic.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ((MyMusicActivity) myContext).setSdCardFlag(false); ((MyMusicActivity) myContext).onCreate(null); } }); myMusic.setId(1); // 设置ID为1 ImageView myStorage = new ImageView(context); myStorage.setImageResource(R.drawable.style1_mymusic_usbstore); myStorage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // 设置ListView为显示 ((MyMusicActivity) myContext).setlistViewLinearLayoutVisible(false); // GalleryVisible为隐藏 ((MyMusicActivity) myContext).setGalleryVisible(true); } }); myStorage.setId(2); // 设置id为2 // 设置本地当前目录的按钮 MyImageButton myImageButtonFolderNow = new MyImageButton(context, R.drawable.style1_mymusic_details, ButtonText); RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp1.addRule(RelativeLayout.ALIGN_PARENT_LEFT); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp2.addRule(RelativeLayout.RIGHT_OF, 1);//在控件ID为1的控件的右边 RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp3.addRule(RelativeLayout.RIGHT_OF, 2); footerRelativeLayout.addView(myMusic, lp1); footerRelativeLayout.addView(myStorage, lp2); // 播放按钮 MyImageButton myImageButtonPlay = new MyImageButton(context, R.drawable.mymusic_button_pause_backgroud, "播放"); footerRelativeLayout.addView(myImageButtonFolderNow, lp3); myImageButtonPlay.setId(4); RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp4.addRule(RelativeLayout.LEFT_OF, 5); // 随机按钮 MyImageButton myImageButtonPlayRandom = new MyImageButton(context, R.drawable.mymusic_button_play_random, "随机开"); myImageButtonPlayRandom.setId(5); RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp5.addRule(RelativeLayout.LEFT_OF, 6); // 歌词按钮 MyImageButton myImageButtonLyric = new MyImageButton(context, R.drawable.mymusic_button_lyric, "LRC歌词"); myImageButtonLyric.setId(6); RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp6.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); // 加入 footerRelativeLayout.addView(myImageButtonLyric, lp6); footerRelativeLayout.addView(myImageButtonPlayRandom, lp5); footerRelativeLayout.addView(myImageButtonPlay, lp4); flagAddFooterGuide = false; ?[Copy to clipboard] Downloadzuiniuwang.java 再来个LinearLayout的 ?[Copy to clipboard] Downloadzuiniuwang.java super.onCreate(icicle); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); btn = new Button(this); btn.setId(101); btn.setText("test looper"); btn.setOnClickListener(this); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(100,50); param.topMargin = 10; layout.addView(btn, param); btn2 = new Button(this); btn2.setId(102); btn2.setText("exit"); btn2.setOnClickListener(this); layout.addView(btn2, param); tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setText(""); //其中 FP 是final int FP=LinearLayout.LayoutParams.FILL_PARENT; //final int WC = LinearLayout.LayoutParams.WRAP_CONTENT; LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(FP, WC); param2.topMargin = 10; param2.setMargins(0, 0, 5, 0); //参数分别是(int left, int top, int right, int bottom) layout.addView(tv, param2); setContentView(layout); 一定要记住,创建的Parameter addview时,一定是这个子控件的参数,而不是这个容器本身的参数,这个相当重要,我在此处浪费了不少时间。如果需要对本Layout加入上参数可以 layout.setLayoutParams( XXX params) 和 layout.setXXX 便可。 本文转自 最牛傻蛋 51CTO博客,原文链接:http://blog.51cto.com/zuiniuwang/720070,如需转载请自行联系原作者

优秀的个人博客,低调大师

hbase 报文 处理 逻辑

报文格式: 每隔一个小时 出现一个文件类型 报文 ,所以 我们的处理思路是,一个小时做一次处理。 import java.io.FileInputStream; import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import com.cmcc.aoi.util.OsUtil; public class HbaseStarter { public static void main(String[] args) throws Exception { Properties properties=new Properties(); String config=""; if(!OsUtil.isLinux()) config= "D:/work/util/aoi-hbase/trunk/src/main/resources/config.properties"; else config = "/home/aoi/aoi-hbase/conf/config.properties"; FileInputStream fis = new FileInputStream(config); properties.load(fis); fis.close(); String hbaseTable = properties.getProperty("com.cmcc.aoi.ua.hbaseTable"); String hbaseFamily = properties.getProperty("com.cmcc.aoi.ua.hbaseFamily"); String sourceFilePath=properties.getProperty("com.cmcc.aoi.ua.sourceFilePath"); String archivelogsPath=properties.getProperty("com.cmcc.aoi.ua.archivelogsPath"); boolean isDebug= Integer.parseInt( properties.getProperty("com.cmcc.aoi.ua.isDebug")) == 0 ? false : true; String sourceFileName = properties.getProperty("com.cmcc.aoi.ua.sourceFileName"); String[] hbaseTableName=hbaseTable.split(","); // table String[] hbaseFamilyName=hbaseFamily.split("&");// family String[] sourceFileNameArr=sourceFileName.split(","); ScheduledExecutorService service = Executors.newScheduledThreadPool(2); service.scheduleAtFixedRate(new DeviceReadThread (sourceFileNameArr[0],hbaseTableName[0],hbaseFamilyName[0].split(","),sourceFilePath,archivelogsPath,isDebug) ,0, 1,TimeUnit.HOURS); service.scheduleAtFixedRate(new AppReadThread (sourceFileNameArr[1],hbaseTableName[1],hbaseFamilyName[1].split(","),sourceFilePath,archivelogsPath,isDebug) ,0, 1,TimeUnit.HOURS); } } import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import Model.Device; import com.alibaba.fastjson.JSON; public class DeviceReadThread extends BaseRunnabler { static Logger logger = LoggerFactory.getLogger(DeviceReadThread.class); public DeviceReadThread(String sourceFileName, String hbaseTable, String[] hbaseFamily, String sourceFilePath, String archivelogsPath, boolean isDebug) { super(sourceFileName, hbaseTable, hbaseFamily, sourceFilePath, archivelogsPath, isDebug); } public void processFile(IOperator hu) { FileReader logReader = null; BufferedReader logBufferedReader = null; try { File logFile = new File(sourceFilePath+sourceFileName); logReader = new FileReader(logFile); logBufferedReader = new BufferedReader(logReader); String temp = logBufferedReader.readLine(); //logger.error(" temp is " + temp ); while ( temp != null) { Device device = JSON.parseObject(temp, Device.class); //logger.error(" device is null ? " + ( device == null ) ); String[][] s = new String[][] { { device.getLid(), hbaseFamily[0], "lid" , device.getLid() } , { device.getLid(), hbaseFamily[1], "date", (new Date()).toString() }, { device.getLid(), hbaseFamily[2], "os", device.getOs() }, { device.getLid(), hbaseFamily[2], "osv", device.getOsv()} }; hu.writeMultRow(hbaseTable, s); logger.info(" hbase util end " ); temp = logBufferedReader.readLine(); } } catch (Exception e) { logger.error(" DeviceReadThread error " ); e.printStackTrace(); } finally { try { logBufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } try { logReader.close(); } catch (IOException e) { e.printStackTrace(); } } } } import java.io.File; import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.cmcc.aoi.util.FileUtil; public abstract class BaseRunnabler implements Runnable{ protected static Logger logger = LoggerFactory.getLogger(BaseRunnabler.class); String sourceFileName=""; // 读取文件路径 String hbaseTable=""; // hbase 表名 String [] hbaseFamily=null; // 行列簇名 String sourceFilePath ; String archivelogsPath ; boolean isDebug; public BaseRunnabler(String sourceFileName,String hbaseTable,String [] hbaseFamily ,String sourceFilePath,String archivelogsPath,boolean isDebug ){ this.hbaseTable=hbaseTable; this.hbaseFamily = hbaseFamily; this.sourceFileName=sourceFileName; this.sourceFilePath = sourceFilePath; this.archivelogsPath = archivelogsPath; this.isDebug = isDebug; } @Override public void run() { try{ IOperator hu = new HbaseUtil( hbaseTable,hbaseFamily); hu.createTable(hbaseTable,hbaseFamily ); File file=new File(sourceFilePath); File[] tempFileList = file.listFiles(); Arrays.sort(tempFileList); for (File tempFile: tempFileList) { if (tempFile.isFile() && tempFile.getName().contains(sourceFileName +".") ) { try{ try{ processFile(hu); }catch (Exception e) { logger.error("readfile error ,must continue to protect to read other file "); continue; } removeFile(tempFile); }catch (Exception e2) { logger.error(" one file has an error ,other file must continue to do this task "); } } } }catch (Exception e) { e.printStackTrace(); } } public abstract void processFile(IOperator hu) throws Exception; private void removeFile(File file) { if (isDebug) { File path = new File(archivelogsPath); if (!path.exists()) { path.mkdirs(); } FileUtil.moveFile(file, new File(archivelogsPath,file.getName())); logger.info("remove file :" + file.getName()); }else{ file.delete(); logger.info("delete file :" + file.getName()); } } } 捐助开发者 在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。 谢谢您的赞助,我会做的更好!

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册