Android平板电脑开发— — —碎片

碎片是一种可以嵌入在活动中的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);    }}


				
时间: 2024-07-30 15:15:32

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

【电子书下载】《Android应用程序开发与典型案例》完整版!!

图书简介: <android应用程序开发与典型案例>共23章,内容包含两大部分.第一部分是android程序设计基础,在介绍android环境搭建以及android系统基本控件和组件后,详细介绍了android系统应用编程中典型的技术,比如,android中的图形图像.多媒体编程.gps定位与地图编程等:第二部分是android程序ui设计,从手机软件的交互设计谈起,介绍了android用户界面设计原则和方法.android用户界面设计哲学等,并给出了具体建议. <android应用程序

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

Android开发:碎片Fragment完全解析 为了让界面可以在平板上更好地展示,Android在3.0版本引入了Fragment(碎片)功能,它非常类似于Activity,可以像 Activity一样包含布局.Fragment通常是嵌套在Activity中使用的,现在想象这种场景:有两个 Fragment,Fragment 1包含了一个ListView,每行显示一本书的标题.Fragment 2包含了TextView和 ImageView,来显示书的详细内容和图片. AD:51CTO学院:I

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

项目中有个图片在平板电脑中显示特别小的原因,一直苦于没找到原因,也没有平板电脑测试,今天找了个修改分辨率的,编写相关方法终于处理了,记录下比较: 好让以后不造轮子. 主要是获取文章相关图片显示问题,直接用getIntrinsicWidth()方法获取,getIntrinsicWidth()获取的并非图片的实际宽度,在手机看还过得去,不会相差太远,但在平板电脑看, 它简直就是一个小女孩,太害羞了,以至于显示那么小. 回到正题: 解决方法: 1.获取手机分辨率 用该分辨率乘以其密度 if (file

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

Android从诞生开始就受到热捧,并日益普及.它有别于以往的手机及移动终端操作系统,其独具的开源性.系统廉价性和提供给第三方大自由度的创新空间,以及不受硬件约束的优势,获得了广大开放社群的支持.但是系统碎片化和收益不高等问题日益严重,正在逐渐被开发者所抛弃. Google推出的新一代网上平台Android Market,让开发者轻松地进入这个“市场”,手机用户可在该平台寻找.购买.下载使用Android操作系统的手机应用程序和其他内容,也可在Android Market上销售自己的软件,并通过

调研Android平台的开发环境的发展演变

一.发展演变 1.Android版本进化史 阿童木(Android beta)和发条机器人(Android1.0)->Cupcake(Android1.5)->Dount(Android1.6)->Eclair(Android2.0/2.1)->Froyo(Android2.2/2.2.1)->Gingerbread(Android2.3.x)->Honeycomb(Android3.0/3.1/3.2)->Ice Cream Sandwich(Android4.

平板电脑进化论:从玩具到工具

作为娱乐设备,平板电脑正在走向死亡.这并非是危言耸听,而是正在发生的市场行情.据CNBC最新报告显示,苹果2014全年的iPad销量将迎其问市五年来的首次下滑.预测研究数据显示,2014年iPad的销量大约只有6800万部,而2013年苹果iPad则卖出了7400万部.今日之果,昨日只因.如果我们还能记得五年前平板电脑如何兴起的,那么应当更容易理解,为什么会有今天的萧条. iPad:让平板从概念走向现实 说起平板电脑的历史,还得从iPad说起.虽然有诸如Table PC这样的史前传说,它们的诞生

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

http://blog.csdn.net/qwert1213131/article/details/38068379 本文属于个人理解,能力有限,纰漏在所难免,还望指正! [小鱼有点电] [Espruino中文社区] 本节内容主要是讲如何用平板电脑调试Espruino,附带一个例子,调试74hc595芯片(下节内容再讲).我用的是nexus 7平板,使用OTG线连接你的开发板,需要安装AndroidScript软件,安装包在此,感谢QQ群里kk大哥提供哈! 首先安装完Android Script

Android简介与开发环境

一.什么是Android与Android平台架构介绍 Android是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统,它包括一个操作系统,中间件和一些重要的应用程序. 采用软件堆层(Software Stack,又名软件叠层)的架构,主要分为三部分. 底层以Linux内核工作为基础,由C语言开发,只提供基本功能 中间层包括函数库Library和Dalvik虚拟机,由C++开发. 最上层是各种应用软件,包括通话程序,短信程序等,应用软件则由各公司自行开发,以Java作

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

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/53173217 有几天没有更新博客了,不过本篇却准备了许久,希望能带给每一位开发者最简单高效的学习方式.废话到此为止,下面开始正文. NFC(Near Field Communication,近场通信)是一种数据传输技术.与Wi-Fi.蓝牙.红外线等数据传输技术的一个主要差异就是有效距离一般不能超过4厘米.但是NFC传输速度要比红外快.目前NFC已经出现了一些应用,例如电子标签识别