Creating a Fragment Download the sample FragmentBasics.zip
developer.android.com/shareables/training/FragmentBasics.zip
Creating a Fragment
Previous Next
This lesson teaches you to
Create a Fragment Class
Add a Fragment to an Activity using XML
You should also read
Fragments
Try it out
Download the sample
FragmentBasics.zip
You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities). This lesson shows how to extend the Fragment class using the Support Library so your app remains compatible with devices running system versions as low as Android 1.6.
Note: If you decide that the minimum API level your app requires is 11 or higher, you don't need to use the Support Library and can instead use the framework's built in Fragment class and related APIs. Just be aware that this lesson is focused on using the APIs from the Support Library, which use a specific package signature and sometimes slightly different API names than the versions included in the platform.
Before you begin this lesson, you must set up your Android project to use the Support Library. If you have not used the Support Library before, set up your project to use the v4 library by following the Support Library Setup document. However, you can also include the action bar in your activities by instead using the v7 appcompat library, which is compatible with Android 2.1 (API level 7) and also includes the Fragment APIs.
Create a Fragment Class
To create a fragment, extend the Fragment class, then override key lifecycle methods to insert your app logic, similar to the way you would with an Activity class.
One difference when creating a Fragment is that you must use the onCreateView() callback to define the layout. In fact, this is the only callback you need in order to get a fragment running. For example, here's a simple fragment that specifies its own layout:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.ViewGroup;
public class ArticleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.article_view, container, false);
}
}
Just like an activity, a fragment should implement other lifecycle callbacks that allow you to manage its state as it is added or removed from the activity and as the activity transitions between its lifecycle states. For instance, when the activity's onPause() method is called, any fragments in the activity also receive a call to onPause().
More information about the fragment lifecycle and callback methods is available in the Fragments developer guide.
Add a Fragment to an Activity using XML
While fragments are reusable, modular UI components, each instance of a Fragment class must be associated with a parent FragmentActivity. You can achieve this association by defining each fragment within your activity layout XML file.
Note: FragmentActivity is a special activity provided in the Support Library to handle fragments on system versions older than API level 11. If the lowest system version you support is API level 11 or higher, then you can use a regular Activity.
Here is an example layout file that adds two fragments to an activity when the device screen is considered "large" (specified by the large qualifier in the directory name).
res/layout-large/news_articles.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.example.android.fragments.HeadlinesFragment"
android:id="@+id/headlines_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.android.fragments.ArticleFragment"
android:id="@+id/article_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
Tip: For more about creating layouts for different screen sizes, read Supporting Different Screen Sizes.
Then apply the layout to your activity:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_articles);
}
}
If you're using the v7 appcompat library, your activity should instead extend ActionBarActivity, which is a subclass of FragmentActivity (for more information, read Adding the Action Bar).
Note: When you add a fragment to an activity layout by defining the fragment in the layout XML file, you cannot remove the fragment at runtime. If you plan to swap your fragments in and out during user interaction, you must add the fragment to the activity when the activity first starts, as shown in the next lesson.
ffmpeg最新版 windows版本 可以执行文件
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Getting help:
-h -- print basic options
-h long -- print more options
-h full -- print all options (including all format and codec specific options, very long)
See man ffmpeg for detailed description of the options.
Print help / information / capabilities:
-L show license
-h topic show help
-? topic show help
-help topic show help
--help topic show help
-version show version
-buildconf show build configuration
-formats show available formats
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
Global options (affect whole program instead of just one file:
-loglevel loglevel set logging level
-v loglevel set logging level
-report generate a report
-max_alloc bytes set maximum size of a single allocated block
-y overwrite output files
-n never overwrite output files
-stats print progress report during encoding
-max_error_rate ratio of errors (0.0: no errors, 1.0: 100% error maximum error rate
-bits_per_raw_sample number set the number of bits per raw sample
-vol volume change audio volume (256=normal)
Per-file main options:
-f fmt force format
-c codec codec name
-codec codec
android-support-v13.jar
android-support-v13.jar
android-support-v7-gridlayout.jar
The import android.support.v7 cannot be resolved
下载
android-support-v13.jar
android-support-v7-gridlayout.jar
然后在Build Path里的Add External Jar...中添加jar包后,即可使用里面的接口
本下载只包含android-support-v7-gridlayout.jar
android-support-v13.jar在我的另外一个资源里
android 全景图片展示
android 全景 图片展示 手动触控可以用
Android 三维全景图片展示 PanoramaGL 源码
Android 三维全景图片展示 PanoramaGL 源码 , 亲测,可以用,可以考虑加入传感器,重力感应,进行全景图片的展示。
android界面编程基础
android界面编程基础,以及事件处理
android编程 android编程入门 android开发 android软件
目录
一、 简述 2
二、 应用程序的组成元素 2
1. Activity元素 2
2. Service元素 3
3. Broadcast receivers元素 3
4. Content providers元素 3
(一) 元素的激活 3
(二) 元素的去激活 4
(三) Manifest文件 4
(四) Intent 筛选 5
三、 Activity和Task 6
(一) Affinities和新Task 7
(二) 运行模式 7
(三) 清除Stack(Task) 8
(四) 开始Task 9
四、 进程和线程 9
(一) 进程 9
(二) 线程 10
(三) 远程过程调用 10
(四) 线程安全方法 11
五、 元素的生命周期 11
(一) Activity的生命周期 11
1. Activity状态的保存 14
(二) Service的生命周期 14
(三) Broadcast receiver的生命周期 15
(四) 进程的生命周期 15
BREW_UI_Widgets_API_Reference.chm
BREW_UI_Widgets_API_Reference.chm
Buiw开发文档
LINUX系统管理白皮书.zip
经典LINUX书籍汇总之一
LINUX系统管理白皮书.zip
LINUX系统管理白皮书.zip
LINUX系统管理白皮书.zip
嵌入式开发课件完全教程,总共十一课,都在我上传,有序号5
嵌入式开发课件完全教程,总共十一课,都在我上传,有序号5
嵌入式开发课件完全教程,总共十一课,都在我上传,有序号
嵌入式开发课件完全教程,总共十一课,都在我上传,有序号
嵌入式开发课件完全教程
嵌入式开发课件完全教程,总共十一课,都在我上传,有序号
ARM开发流程.pdf
ARM开发流程.pdf
ARM开发流程.pdf
ARM开发流程.pdf
嵌入式LINUX开发入门.pdf
嵌入式LINUX开发入门
学习嵌入式LINUX开发,必须注意学习的方式和方法!就把这个嵌入式开发板当作一台WINDOWS PC,就像用VC一样在上面做开发(只是开发模式由原来完全的本地开发变成宿主机--目标板的模式了)。绝对不要去盲目阅读LINUX内核分析之类的书籍,对于初学者一两年内根本用不到这个!就像在WINDOWS下开发永远不要关心WINDOWS内核一个道理,不要因为LINUX内核是源代码开放的,就非要去研究LINUX内核。90%的开发人员关心的还是“外设接口驱动+应用程序(如GUI)”,所以对于初学者,进入嵌入式LINUX开发的殿堂,必须迈过如下两个台阶:
嵌入式开发 LINUX 第二课
嵌入式开发 LINUX第二课
2-1设备管理.ppt
2-2Linux网络应用.ppt
2-3进 程 管 理.ppt
2-4Linux编程基础.ppt
嵌入式系统开发 LINUX 第一课
嵌入式系统开发 LINUX 第一课
主要介绍 Linux嵌入式开发的原理和简介
经典的个人管理文档-如何掌控自己的时间和生活
《如何掌控自己的时间和生活》最新光盘培训版.ppt