[翻译]API Guides - Layouts
官方文档地址:http://developer.android.com/guide/topics/ui/declaring-layout.html
PS:API Guides里面的内容不免都简单些,翻译还是很渣,明明知道意思,但按着它的原话翻感觉就是很怪……
- 在XML中定义UI元素。Android提供了一个直截了当的XML词汇表,与那些小控件,布局的视图类以及它们的子类关联。
- 在运行时实例化布局元素。你的应用可以通过编程的方式创建View和ViewGroup对象(并且操纵它们的属性)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextViewandroid:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView"/>
<Buttonandroid:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button"/>
</LinearLayout>
publicvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
}
android:id="@+id/my_button"
android:id="@android:id/empty"
<Buttonandroid:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_button_text"/>
Button myButton =(Button) findViewById(R.id.my_button);


- wrap_content 告诉你的view,它的尺寸必须要包住里面的内容。
- fill_parent(在API LEVEL 8 改名为match_parent) 告诉view必须要和父ViewGroup有一样的大小。










ArrayAdapter adapter =newArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, myStringArray);
ListView listView =(ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
String[] fromColumns ={ContactsContract.Data.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
int[] toViews ={R.id.display_name, R.id.phone_number};
SimpleCursorAdapter adapter =newSimpleCursorAdapter(this,
R.layout.person_name_and_number, cursor, fromColumns, toViews,0);
ListView listView = getListView();
listView.setAdapter(adapter);
// Create a message handling object as an anonymous class.
privateOnItemClickListener mMessageClickedHandler =newOnItemClickListener(){
publicvoid onItemClick(AdapterView parent,View v,int position,long id){
// Do something in response to the click
}
}; listView.setOnItemClickListener(mMessageClickedHandler);
[翻译]API Guides - Layouts的更多相关文章
- [翻译]API Guides - Bound Services
官方文档原文地址:http://developer.android.com/guide/components/bound-services.html 一个Bound Service是一个客户端-服务器 ...
- [翻译]API Guides - Service
官方文档原文地址:http://developer.android.com/guide/components/services.html Service是应用程序组件之一,它并不提供一个用户界面,可以 ...
- C# 调用百度翻译Api
这是简单的界面.用的是wpf,winform也可以 具体的操作类 public partial class MainWindow : Window { string url = "" ...
- 基于百度翻译API开发属于自己的翻译工具
你是否每天使用着网页翻译工具?你是否遇到过这种情况,上网过程中遇到一个很长的单词但是又不能复制,要开两个浏览器,一个打开百度翻译,照着另一个网页输入单词?你安装了各种翻译软件后,又删除,只因忍受不了那 ...
- Python 调用百度翻译API
由于实习公司这边做的是日文app,有时要看看用户反馈,对于我这种五十音图都没记住的人,表示百度翻译确实还可以.但不想每次都复制粘贴啊,google被墙也是挺蛋疼的事,所以用python结合baidu ...
- Android API Guides 学习笔记---Application Fundamentals(一)
今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1. App ...
- [Python] 使用有道翻译API
Python 使用youdao (有道翻译)API 想写一个给自己记录背单词状况的软件,需要获取英文单词的中文释义(基本功能).考虑使用有道翻译的API实现获取英文单词的中文释义的方法. 获取API_ ...
- 记微信开发(有道翻译api)
记微信开发(有道翻译api) 记微信开发(有道翻译api) 效果: 有道翻译api申请: 地址:http://fanyi.youdao.com/openapi code: <?php/** * ...
- 有道翻译API
轻奢侈品_百度百科 轻奢侈品 有道翻译API 有道翻译API申请成功 API key:72763558 keyfrom:lexus-studio
随机推荐
- 配置redis一直启动
1. 进入 DOS窗口 2. 在进入redis的安装目录 3. 输入:redis-server --service-install redis.windows.conf --loglevel verb ...
- ios retainCount
retainCount Important: Typically there should be no reason to explicitly ask an object what its reta ...
- 记账本APP(2)
今天下载了Hbuiler,生成了一个记账本APP,目前里面只可以 输入今日消费 明天将会做出来记录以及计算总额于月消费.
- 【commons】邮件发送工具——commons-email
一.概述 直接通过官网的overview进行了解,一句话概括如下: Commons Email aims to provide a API for sending email. It is built ...
- 20155230 实验二《Java面向对象程序设计》实验报告
20155230 实验二<Java面向对象程序设计>实验报告 一.单元测试 三种代码 知道了伪代码.产品代码.测试代码的关系和用途,并根据老师的例子,按测试代码调试了产品代码. 值得注意的 ...
- 20155233 2016-2017-2《Java程序设计》课程总结
20155233 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:预习去写博客,如何达到理想的师生关系. 预备作业2:对自己C语言的学习进行了解与认识. ...
- 20155236 2016-2017-2 《Java程序设计》第十周学习总结
20155236 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情就是把数据发 ...
- 20155310 2016-2017-2《Java程序设计》课堂实践补交
20155310 2016-2017-2<Java程序设计>课堂实践补交 第九周 程序设计中临时变量的使用 public class linshibianliang { public st ...
- 【转载】值得推荐的C/C++框架和库
原文:值得推荐的C/C++框架和库 值得学习的C语言开源项目 Libevent libev是一个开源的事件驱动库,基于epoll,kqueue等OS提供的基础设施.其以高效出名,它可以将IO事件,定时 ...
- HBase核心功能模块--读书笔记
客户端Client 客户端 Client 是整个 HBase 系统的入口.使用者直接通过客户端操作 HBase.客户端 使用 HBase 的 RPC 机制与 HMaster 和 RegionServe ...