第一范文网 - 专业文章范例文档资料分享平台

Android控件大全以及各布局空间的使用方式

来源:用户分享 时间:2025/5/15 22:33:31 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

import android.widget.LinearLayout; import android.widget.TextView;

public class Main extends Activity {

/** Called when the activity is first created. */ @Override

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

// 将指定的布局文件作为 Activity 所显示的内容 setContentView(R.layout.main);

// 动态地在指定的容器控件上添加新的控件 TextView txt = new TextView(this); txt.setText(\动态添加控件\ // setContentView(txt);

((LinearLayout)this.findViewById(R.id.layout)).addView(txt);

// 引用资源文件内的内容作为输出内容

TextView txt1 = (TextView)this.findViewById(R.id.txt); txt1.setText(this.getString(R.string.hello2)); } }

四、系出名门Android(2) - 布局(Layout)和菜单(Menu)

介绍

在 Android 中各种布局的应用,以及菜单效果的实现 ? ?

各种布局方式的应用,FrameLayout, LinearLayout, TableLayout, AbsoluteLayout, 为指定元素配置上下文菜单,为应用程序配置选项菜单,以及多级菜单的实现 RelativeLayout

1、各种布局方式的演示(FrameLayout, LinearLayout, TableLayout,

AbsoluteLayout, RelativeLayout) res/layout/main.xml 代码

layout_width - 宽。fill_parent: 宽度跟着父元素走;wrap_content: 宽度跟着本身的内容走;直接指定一个 px 值来设置宽

layout_height - 高。fill_parent: 高度跟着父元素走;wrap_content: 高度跟着本身的内容走;直接指定一个 px 值来设置高 -->

android:layout_width=\

android:layout_height=\

android:layout_height=\

android:layout_height=\

android:layout_width=\

android:collapseColumns=\

android:layout_weight=\ android:text=\行1列1\

android:layout_weight=\ android:text=\行1列2\

android:layout_weight=\ android:text=\行1列3\

android:layout_height=\行2列1\

android:layout_height=\ android:layout_x=\ android:layout_y=\

android:layout_width=\

android:layout_height=\ android:layout_centerInParent=\

android:layout_height=\ android:layout_marginLeft=\

android:layout_height=\

android:layout_below=\

res/values/strings.xml

Main.java 代码

package com.webabcd.layout;

import android.app.Activity; import android.os.Bundle;

public class Main extends Activity {

/** Called when the activity is first created. */ @Override

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

2、上下文菜单,选项菜单,子菜单

res/layout/main.xml 代码

Android控件大全以及各布局空间的使用方式.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5ykos29qmq4bptb10m3b_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top