云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Android控件大全以及各布局空间的使用方式

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/7 18:09:50

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 代码

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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);

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com