• 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.

    0
    34
    663KB
    2015-02-14
    3
  • 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 codec name -pre preset preset name -map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile -t duration record or transcode "duration" seconds of audio/video -to time_stop record or transcode stop time -fs limit_size set the limit file size in bytes -ss time_off set the start time offset -timestamp time set the recording timestamp ('now' to set the current time) -metadata string=string add metadata -target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...) -apad audio pad -frames number set the number of frames to output -filter filter_graph set stream filtergraph -filter_script filename read stream filtergraph description from a file -reinit_filter reinit filtergraph on input parameter changes -discard discard -disposition disposition Video options: -vframes number set the number of video frames to output -r rate set frame rate (Hz value, fraction or abbreviation) -s size set frame size (WxH or abbreviation) -aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) -bits_per_raw_sample number set the number of bits per raw sample -vn disable video -vcodec codec force video codec ('copy' to copy stream) -timecode hh:mm:ss[:;.]ff set initial TimeCode value. -pass n select the pass number (1 to 3) -vf filter_graph set video filters -ab bitrate audio bitrate (please use -b:a) -b bitrate video bitrate (please use -b:v) -dn disable data Audio options: -aframes number set the number of audio frames to output -aq quality set audio quality (codec-specific) -ar rate set audio sampling rate (in Hz) -ac channels set number of audio channels -an disable audio -acodec codec force audio codec ('copy' to copy stream) -vol volume change audio volume (256=normal) -af filter_graph set audio filters Subtitle options: -s size set frame size (WxH or abbreviation) -sn disable subtitle -scodec codec force subtitle codec ('copy' to copy stream) -stag fourcc/tag force subtitle tag/fourcc -fix_sub_duration fix subtitles duration -canvas_size size set canvas size (WxH or abbreviation) -spre preset set the subtitle options to the indicated preset

    5
    716
    11.47MB
    2015-02-05
    50
  • android-support-v13.jar

    android-support-v13.jar

    0
    21
    251KB
    2015-02-02
    3
  • 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在我的另外一个资源里

    0
    31
    38KB
    2015-02-02
    4
  • android 全景图片展示

    android 全景 图片展示 手动触控可以用

    0
    100
    4.06MB
    2015-01-29
    13
  • Android 三维全景图片展示 PanoramaGL 源码

    Android 三维全景图片展示 PanoramaGL 源码 , 亲测,可以用,可以考虑加入传感器,重力感应,进行全景图片的展示。

    5
    562
    3.38MB
    2015-01-29
    43
  • android界面编程基础

    android界面编程基础,以及事件处理

    0
    52
    42KB
    2010-06-13
    0
  • 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

    4
    111
    343KB
    2010-06-03
    10
  • BREW_UI_Widgets_API_Reference.chm

    BREW_UI_Widgets_API_Reference.chm Buiw开发文档

    0
    18
    975KB
    2009-07-29
    5
  • LINUX系统管理白皮书.zip

    经典LINUX书籍汇总之一 LINUX系统管理白皮书.zip LINUX系统管理白皮书.zip LINUX系统管理白皮书.zip

    0
    50
    6.84MB
    2009-07-28
    0
关注 私信
上传资源赚积分or赚钱