碎片是一种可以嵌入在活动中的UI片段,它能让程序更加合理与充分地使用大屏幕的空间,碎片通常都是在平板电脑开发中才会使用

简单实例


左碎片布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="center"/> </LinearLayout>


package com.example.fragmenttest;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by Administrator on 2016/3/2.
*/
public class LeftFragment extends Fragment { @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.left_fragment,container,false);
return view;
}
}

右碎片布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"> <TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a text"
android:textSize="20sp"
android:layout_gravity="center"/> </LinearLayout>

package com.example.fragmenttest;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by Administrator on 2016/3/2.
*/
public class RightFragment extends Fragment { @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.right_fragment,container);
return view;
}
}

主界面
<?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" > <fragment
android:id="@+id/left_fragment"
android:name="com.example.fragmenttest.LeftFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/> <fragment
android:id="@+id/right_fragment"
android:name="com.example.fragmenttest.RightFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/> </LinearLayout>

package com.example.fragmenttest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}


												

Android平板电脑开发— — —碎片的更多相关文章

  1. 价格战拉上了Android平板电脑

    自从苹果iPad成功以来,平板电脑一直是人们争相追捧的热门产品.其中Android平板电脑已是遍地开花.去年,在移动行业,主流厂商已推出了太多各种款型的Android平板电脑,它们留给2014年的创新 ...

  2. Android控件开发——ListView

    上篇博客解决了Android客户端通过WebService与服务器端程序进行交互的问题,这篇博客重点关注两个问题,一个是Android应用程序如何与本机文件型数据库SQLite进行交互,另一问题则是如 ...

  3. Android开发:碎片Fragment完全解析fragment_main.xml/activity_main.xml

    Android开发:碎片Fragment完全解析   为了让界面可以在平板上更好地展示,Android在3.0版本引入了Fragment(碎片)功能,它非常类似于Activity,可以像 Activi ...

  4. Android获取图片实际大小兼容平板电脑

    项目中有个图片在平板电脑中显示特别小的原因.一直苦于没找到原因,也没有平板电脑測试,今天找了个改动分辨率的,编写相关方法最终处理了,记录下比較: 好让以后不造轮子. 主要是获取文章相关图片显示问题.直 ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:手机、平板电脑、台式电脑

    <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 手机.平板电脑.台式电脑</title&g ...

  6. android: 动态加载碎片布局的技巧

    虽然动态添加碎片的功能很强大,可以解决很多实际开发中的问题,但是它毕竟只是在 一个布局文件中进行一些添加和替换操作.如果程序能够根据设备的分辨率或屏幕大小在运 行时来决定加载哪个布局,那我们可发挥的空 ...

  7. Android从开源到碎片化 开发者叛离的真相

    Android从诞生开始就受到热捧,并日益普及.它有别于以往的手机及移动终端操作系统,其独具的开源性.系统廉价性和提供给第三方大自由度的创新空间,以及不受硬件约束的优势,获得了广大开放社群的支持.但是 ...

  8. Android NFC标签 开发深度解析 触碰的艺术

    有几天没有更新博客了,不过本篇却准备了许久,希望能带给每一位开发者最简单高效的学习方式.废话到此为止,下面开始正文. NFC(Near Field Communication,近场通信)是一种数据传输 ...

  9. 【Espruino】NO.17 使用平板电脑调试Espruino(OTG方式)

    http://blog.csdn.net/qwert1213131/article/details/38068379 本文属于个人理解,能力有限,纰漏在所难免,还望指正! [小鱼有点电] [Espru ...

随机推荐

  1. Super Ugly Number

    eg 2,3,5 把第一个元素(2,1)放到最小堆,2表示乘积,1表示乘数   乘数     队列                          最小堆                   即将进 ...

  2. chrome表单自动填充去掉input黄色背景解决方案

    设置css代码如下: input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset; } 参考文章:http://bl ...

  3. 计算字符串中al_num,spance_num,digit_num,other_num的个数

    def jisuan(x) : al_num = 0 spance_num = 0 digit_num = 0 other_num = 0 for i in x : if i.isdigit() : ...

  4. winform开发框架之模块维护

    前言:模块维护试图解决的问题, 模块加载只用MEF的方式: MEF(Managed Extensibility Framework)是一个用于创建可扩展的轻型应用程序的库. 应用程序开发人员可利用该库 ...

  5. signtool

    https://msdn.microsoft.com/en-us/library/8s9b9yaz(v=vs.110).aspx C:\Users\Administrator\.nuget\packa ...

  6. UVa 11300 Spreading the Wealth(有钱同使)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...

  7. WebClient上传音频文件

    //WebClient上传音频文件 public string UploadVoice(string fileNamePath) { Voice model=new Voice(); string s ...

  8. 解决Jenkins console输出乱码

    背景 Jenkins console输出乱码,如 ������������� 1 解决办法 Jenkins Master 设置utf8 encoding Tomcat 启动脚本 export JAVA ...

  9. 《BI项目笔记》历年感官评吸质量均值变化分析Cube的建立

    分析主题主要维度:烟叶级别.烟叶级别按等级信息.烟叶级别按分级标准(标准维度)产地(父子维度)检测时间(时间维度,以Tqc_Raw_SmokingTest .CheckTime字段派生CheckDat ...

  10. 将php网站移到CentOS 6.7上[一]:yum安装lamp环境

    最近应老师要求,将一个网站从51php上转移到学校提供的服务器上,之前对Linux没有了解,一切都在百度百度百度.于是发现很多步骤自己做过后就忘了,现将有效步骤记录下来,以供下次参考. 原51php上 ...