重温7 布局相关
来源:互联网 发布:文明5 mac mod文件夹 编辑:程序博客网 时间:2024/06/05 05:29
1、LinearLayout
可以在控件中使用:
android:layout_weight="1"android:layout_width="0dp"设置控件占屏幕宽度,上表示占屏幕1/2。
2、TableLayout
<TableLayoutandroid:stretchColums="1"...>上指定为1表示拉伸第2列,指定为0表示拉伸第1列
<Buttonandroid:layout_span="2".../>指定控件所占列数,上表示占两列的空间。
3、创建自定义控件 XML、java、include标签
java:
加载布局后
LayoutInflater.from(context).inflate(R.layout.title, this);
优:可以在代码中设置点击事件
package com.example.comeonlinearlayouttitle;import android.content.Context;import android.util.AttributeSet;import android.view.LayoutInflater;import android.widget.LinearLayout;import android.widget.Button;import android.view.View;import android.annotation.SuppressLint;import android.app.Activity;@SuppressLint("NewApi")public class TitleLayout extends LinearLayout{public TitleLayout(Context context) {super(context);// TODO Auto-generated constructor stub}public TitleLayout(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubLayoutInflater.from(context).inflate(R.layout.title, this);Button back_btn = (Button)findViewById(R.id.back);back_btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View view){//Context android.view.View.getContext()//Returns the context the view is running in((Activity) getContext()).finish();}});}public TitleLayout(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}}在XML中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <com.example.comeonlinearlayouttitle.TitleLayout android:layout_height="wrap_content" android:layout_width="match_parent"> </com.example.comeonlinearlayouttitle.TitleLayout> </LinearLayout><!-- <include layout="@layout/title"/> -->在XML中写,使用include标签
<include layout="@layout/title_layout"/>
完整代码在:https://github.com/HiSunny/ComeOnTitle.git
0 0
- 重温7 布局相关
- 重温 linux内存布局
- 重温Flex布局
- SIP-T 相关 RFC 重温
- Android 技术重温系列 (9)- 布局
- 重温6 ListView相关|单位dp/sp
- 重温圣杯布局和双飞翼布局
- 重温
- 布局相关
- 布局相关
- 布局相关
- 布局相关
- SQL教程重温(7)
- 边界布局相关代码
- android布局相关网站
- 相对布局相关属性
- Android 布局相关
- Android布局相关
- Oracle PL/SQL之DDL导致的隐式提交
- ramdisk制作过程记录
- Android自定义adapter的listview
- 读取Assets目录下的数据库
- 基于mfc的对话框编程中,实现控件随对话框大小自动缩放以及通过滚动条实现控件移动功能
- 重温7 布局相关
- 基于C的2048游戏
- eqweqweqwe
- Java内部类的作用
- java伪随机数
- CentOS7安装MariaDB服务无法启动的问题
- Java中ListIterator和Iterator详解与辨析
- Drawable(分辨率)
- 现象的解释