mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
dev
dev

Android Fragment完全解析,关于碎片你所需知道的一切

转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8881711 我们都知道,Android上的界面展示都是通过Activity实现的,Activity实在是太常用了,我相信大家都已经非常熟悉了,这里就不再赘述。 但是Activity也有它的局限性,同样的界面在手机上显示可能很好看,在平板上就未必了,因为平板的屏幕非常大,手机的界面放在平板上可能会有过分被拉长、控件间距过大等情况。这个时候更好的体验效果是在Activity中嵌入"小Activity",然后每个"小Activity"又可以拥有自己的布局。因此,我们今天的主角Fragment登场了。 Fragment初探 为了让界面可以在平板上更好地展示,Android在3.0版本引入了Fragment(碎片)功能,它非常类似于Activity,可以像Activity一样包含布局。Fragment通常是嵌套在Activity中使用的,现在想象这种场景:有两个Fragment,Fragment 1包含了一个ListView,每行显示一本书的标题。Fragment 2包含了TextView和ImageView,来显示书的详细内容和图片。 如果现在程序运行竖屏模式的平板或手机上,Fragment 1可能嵌入在一个Activity中,而Fragment 2可能嵌入在另一个Activity中,如下图所示: 而如果现在程序运行在横屏模式的平板上,两个Fragment就可以嵌入在同一个Activity中了,如下图所示: 由此可以看出,使用Fragment可以让我们更加充分地利用平板的屏幕空间,下面我们一起来探究下如何使用Fragment。 首先需要注意,Fragment是在3.0版本引入的,如果你使用的是3.0之前的系统,需要先导入android-support-v4的jar包才能使用Fragment功能。 新建一个项目叫做Fragments,然后在layout文件夹下新建一个名为fragment1.xml的布局文件:

2016-05-05 0comments 108hotness 0likes mikebai Read all
dev

详细解读DialogFragment

相信看这篇文章的人都应该知道android中的Dialog了吧,如果对于Dialog还不是很了解可以看我之前的一篇详解文章: Dialog详解:http://www.cnblogs.com/tianzhijiexian/p/3867731.html 随着Fragment这个类的引入,Google官方推荐大家使用DialogFragment来代替传统的Dialog,那么是不是说我们之前学习的Dialog知识都没有用处了呢?非也,新的fragment是来方便大家更好的管理和重用Dialog,之前的知识其实都是可以拿来就用的,仅仅需要少许的改变。   一、Dialog和DialogFragment的区别和优劣 新来的DialogFragment让dialog也变成了碎片,相比之前来说应该做了很多优化和处理,对于程序员来看对话框现在更加具体了,就是一个activity上的一个fragment,我们也可以用fragment的知识来管理对话框了。 我们看看之前是怎么运用对话框对象的   AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("Dialog") .setMessage("thisis a dialog") .show();

2016-05-05 0comments 101hotness 0likes mikebai Read all
dev

android studio 中类似VS的代码折叠功能Region

慢慢适应,然后更改设置keymap之后,用起来越来越有vs的fu了 http://www.myandroidsolutions.com/2014/06/21/android-studio-intellij-idea-code-regions/ If you ever worked with Xcode then you must know the power of “#pragma mark” macro. You could just define regions of code using that and sometimes it helps when you have classes that can get a bit big or if you just want to have a nice structure of your class. Well you can do that on Android Studio or IntelliJ IDEA or any of JetBrains’s IDE. Using the steps below you can group your code and name the group however you like and also contract/expand the groups of code. Code without grouping feature 1. Open the IDE you are using

2016-05-05 0comments 110hotness 0likes mikebai Read all
dev

webview中js调用java函数

JAVA部分 this.wvMeaning.addJavascriptInterface(new JavaScriptInterface(this), "Android"); public class JavaScriptInterface{ Context mContext; /** * Instantiate the interface and set the context */ JavaScriptInterface(Context c) { mContext = c; } /** * Show a toast from the web page */ //annotate the callback method with @JavascriptInterface. @JavascriptInterface public void showToast(String toast) { Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); } @JavascriptInterface public void startFunction() { Toast.makeText(TpMeaning.this, "js调用了java函数", Toast.LENGTH_SHORT).show(); runOnUiThread(new Runnable() { @Override public void run() { //msgView.setText(msgView.getText() + "\njs调用了java函数"); } }); } @JavascriptInterface public void startFunction(final String str) { Toast.makeText(TpMeaning.this, str, Toast.

2016-05-05 0comments 106hotness 0likes mikebai Read all
dev

安卓同步联系人选项丢失

修复Android Google账号联系人同步选项丢失 很多国内Android ROM删除了Google服务,需要另外安装,有时安装不完整,导致部分Google账号同步选项丢失。比如在Google账户同步下,找不到同步联系人的选项,导致无法同步Google联系人到手机上。对于Google账号联系人同步选项丢失的问题,可以通过安装丢失的APK来解决。 在http://opengapps.org/根据手机类型,下载完整的GApps包,解压后找到 1 \Core\googlecontactssync.tar.xz 继续解压,最后得到 GoogleContactsSyncAdapter.apk ,复制到手机安装即可。 转载请注明来自 老D,本文标题:修复Android Google账号联系人同步选项丢失, 转载请保留本声明! 标签:Android,Google

2016-04-24 0comments 103hotness 0likes mikebai Read all
dev

C++手稿:静态和全局变量的作用域

全局变量和静态变量的存储方式是一样的,只是作用域不同。如果它们未初始化或初始化为0则会存储在BSS段,如果初始化为非0值则会存储在DATA段,见进程的地址空间分配一文。 静态变量的作用域是当前源文件,全局变量的作用域是整个可执行程序。 值得注意的是: 如果在头文件定义全局变量,在预编译期间#include的头文件会被拷贝进源文件中,编译器是不知道头文件的。 虽然全局变量是全局作用域,但需要extern关键字来声明以通过编译。因为C++是强类型语言,编译时需要根据变量声明做类型检查。 全局变量的引用 C++源文件中引用外部定义的全局变量和引用外部函数是一样的语法,通过extern来声明: // file: a.cpp #include<iostream> extern int a; int main() { std::cout<<b<<std::endl; return 0; } // file: b.cpp #include<iostream> int a = 2; 然后分别编译这两个文件,链接生成a.out并执行它: $ g++ a.cpp b.cpp $ ./a.out b.cpp 2 extern只是在当前文件中声明有这样一个外部变量而已,并不指定它来自哪个外部文件。所以即使extern变量名错误当前源文件也能通过编译,但链接会出错。 头文件中定义 因为头文件可能会被多次引用,在预编译时被引用的头文件会被直接拷贝到源文件中再进行编译。一个常见的错误便是把变量定义放在头文件中,例如下面的变量int a: // file: a.cpp #include <iostream> #include "b.h" int main() { std::cout<<a<<std::endl; return 0; } // file: b.cpp #include<iostream> #include"b.h" void f(){} // file: b.h int a = 2; 头文件b.h中定义了int a,它被a.cpp和b.cpp同时引入。我们将a.cpp和b.cpp分别编译是没有问题的,然后链接时会抛出错误: duplicate symbol _a in: /tmp/ccqpfU5e.o /tmp/ccCRi9nO.o ld: 1 duplicate symbol for architecture x86_64 collect2: error: ld returned 1 exit status 两个.o文件中的_a名称发生了冗余,这是变量重定义错误。 头文件中声明 因为声明操作是幂等的,而多次定义会引发重定义错误。所以 头文件中不应包含任何形式的定义,只应该包含声明, 正确的办法是变量定义总是在源文件中进行,而声明放在头文件中:

2016-04-20 0comments 103hotness 0likes mikebai Read all
dev

C++ - void 与 void*

一、 Void 关键字的使用规则: 1. 如果函数没有返回值,那么应声明为 void 类型; 2. 如果函数无参数,那么应声明其参数为 void; 3. 如果函数的参数可以是任意类型指针,那么应声明其参数为 void * ; 4. void 不能代表一个真实的变量; void 体现了一种抽象,这个世界上的变量都是“有类型”的 二、含义 void 的字面意思是“无类型“,void 则为 ”无类型指针“,void 可以指向任何类型 void 真正发挥的作用在于: 对函数返回的限定 对函数参数的限定 例如: float *p1; int *p2; p1 = p2 #warning 这样会报错:cannot convert from“int*”to “float*”,必须改为p1 = (float *)p2; void *p1; int *p2; p1 = p2; 在 C 语言中,凡是不加返回值类型限定的函数,就会被编译器作为返回整形值处理,例如: add(int a,int b){ return a+b; }

2016-04-20 0comments 105hotness 0likes mikebai Read all
dev

Wave Files

Overview The Wave file format is Windows' native file format for storing digital audio data. It has become one of the most widely supported digital audio file formats on the PC due to the popularity of Windows and the huge number of programs written for the platform. Almost every modern program that can open and/or save digital audio supports this file format, making it both extremely useful and a virtual requirement for software developers to understand. The following specification gives a detailed description of the structure and inner workings of this format. Little-Endian (least significant byte first) order. Data Formats Since the Wave file format is native to Windows and therefor Intel processors, all data values are stored in Strings Wave files may contain strings of text for specifying cue point labels, notes, etc. Strings are stored in a format where the first byte specifies the number of following ASCII text bytes in the string. The following bytes are of course the ASCII character bytes that make up the text string. Pascal programmers will notice that this is the same format used for Pascal strings.   7 'e' 'x' 'a' 'm' 'p' 'l' 'e' Wave String Format Example File Structure Basic Wave File Layout   Chunk ID "RIFF" Chunk Data Size RIFF Type ID "WAVE" Chunk ID "fmt " Chunk Data Size Sample Format Info

2016-04-19 0comments 121hotness 0likes mikebai Read all
dev

WAVE PCM soundfile format

The WAVE file format is a subset of Microsoft's RIFF specification for the storage of multimedia files. A RIFF file starts out with a file header followed by a sequence of data chunks. A WAVE file is often just a RIFF file with a single "WAVE" chunk which consists of two sub-chunks -- a "fmt " chunk specifying the data format and a "data" chunk containing the actual sample data. Call this form the "Canonical form". Who knows how it really all works. An almost complete description which seems totally useless unless you want to spend a week looking over it can be found at MSDN (mostly describes the non-PCM, or registered proprietary data formats). I use the standard WAVE format as created by the sox program: Offset Size Name Description The canonical WAVE format starts with the RIFF header: 0 4 ChunkID Contains the letters "RIFF" in ASCII form (0x52494646 big-endian form). 4 4 ChunkSize 36 + SubChunk2Size, or more precisely: 4 + (8 + SubChunk1Size) + (8 + SubChunk2Size) This is the size of the rest of the chunk following this number. This is the size of the entire file in bytes minus 8 bytes for the two fields not included in this count: ChunkID and ChunkSize. 8 4 Format Contains the letters "WAVE" (0x57415645 big-endian form). The "WAVE" format consists of two subchunks: "fmt " and "data": The "fmt " subchunk describes the sound data's format: 12 4 Subchunk1ID Contains the letters "fmt " (0x666d7420 big-endian form). 16 4 Subchunk1Size 16 for PCM. This is the size…

2016-04-19 0comments 121hotness 0likes mikebai Read all
dev

SPX编解码笔记

采样率 / 取樣頻率(sample rate)  采样率是指从连续信号中每秒钟采集到的采样数量。用Fs kHz来表示,最高频率可表示为Fs/2 kHz(见奈奎斯特Nyquist频率)。  采样定理表明这是信号处理最基本的属性。Speex主要设计了三种不同的采样率:8kHz,16kHz和32kHz。分别表示了窄带、宽带和超宽带。  所謂取樣頻率,就是指要將一秒鐘的聲波分割成幾個點來加以數位化,也就是一秒鐘要取樣幾次:如CD音質的取樣頻率是44.1kHz,  而現今錄音工業,甚至DVD的標準則是96 kHz。

2016-04-18 0comments 111hotness 0likes mikebai Read all
1…89101112…25

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang