Android布局优化之Include(一)

                                                        效果图

                                              


Android布局优化之merge(二)
Android布局优化之ViewStub(三)

Include控件:布局重用
Include标签能够重用布局文件 下面是一个简单的示例:我使用Include布局重用,在主布局文件中重用reuse布局文件中的跑马灯效果(TextVIew跑马灯效果详解请点击) 1.首先新建一个名为reuse的布局文件用于展示TextView跑马灯效果
         <?     xml version=     "1.0"      encoding=     "utf-8"     ?>             <     LinearLayout      xmlns:     android     =     "http://schemas.android.com/apk/res/android"                       android     :layout_width=     "match_parent"                       android     :layout_height=     "match_parent"                       android     :background=     "#C0C0C0"                       android     :orientation=     "vertical"     >                                                                                                                  <     TextView                       android     :id=     "@+id/textView2"                       android     :layout_width=     "wrap_content"                       android     :layout_height=     "wrap_content"                       android     :ellipsize=     "marquee"                       android     :focusable=     "true"                       android     :focusableInTouchMode=     "true"                       android     :marqueeRepeatLimit=     "marquee_forever"                       android     :singleLine=     "true"                       android     :text=     "没有一代人的青春是容易的。                  每一代有每一代人的宿命、委屈、挣扎、奋斗,                  没什么可抱怨的。——白岩松"                        android     :textSize=     "30dp"     />                  LinearLayout     >          

2.在主布局文件activity_main中
           <?      xml version=      "1.0"       encoding=      "utf-8"      ?>                <      RelativeLayout                            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"                            tools      :context=      "com.example.chenxiaoyang.reuselayout.MainActivity"      >                                                   <      include                            android      :id=      "@+id/include"                            layout=      "@layout/reuse"                            android      :layout_width=      "match_parent"                            android      :layout_height=      "match_parent"      />                      RelativeLayout      >                        1.include标签可以使用单独的layout属性,这个也是必须使用的。                     2.可以使用其他属性.include标签若指定了ID属性,而你的layout也定义了ID,则你的layout的ID会被覆盖.                     3.在include标签中所有的Android:layout都是有效的,前提是必须要写layout_width和layout_height两个属性。                     4.布局中可以包含两个相同的include标签                    

更多相关文章

  1. cocos2d-x 2.x版本之win32 window移植android 环境搭配 只用NDK
  2. Android解析xml文件
  3. Android(安卓)API中隐藏的类使用(例如IWindowManager)
  4. 详细整理iOS中UITableView的性能优化
  5. 对android里布局文件当中的TextView对象设置事件监听,但是不响应
  6. Android之Adapter用法总结
  7. android中AVD的使用
  8. mybatisplus的坑 insert标签insert into select无参数问题的解决
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)存储选项之 ContentProvide
  2. android定位布局
  3. Android(安卓)Camera 使用小结
  4. android layout_weight了解
  5. android自定义view属性
  6. Android修改自己程序字体的方法详解
  7. 由Android想到的事情
  8. Android(安卓)常用组件,的常用类型
  9. Android(安卓)Studio中使用android:src="
  10. Android--Selector、shape详解 (