当前位置:首页 > 芯闻号 > 充电吧
[导读]1、LinearLayout可以在控件中使用:android:layout_weight="1" android:layout_width="0dp"设置控件占屏幕宽度,上表示占屏幕1/2。2、Tab

1、LinearLayout

可以在控件中使用:


android:layout_weight="1"
android:layout_width="0dp"

设置控件占屏幕宽度,上表示占屏幕1/2。


2、TableLayout



上指定为1表示拉伸第2列,指定为0表示拉伸第1列




指定控件所占列数,上表示占两列的空间。


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 stub
		LayoutInflater.from(context).inflate(R.layout.title, this);
		
		Button back_btn = (Button)findViewById(R.id.back);
		back_btn.setOnClickListener(new OnClickListener(){
			@Override
			public 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中使用



-->

在XML中写,使用include标签





完整代码在:https://github.com/HiSunny/ComeOnTitle.git

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭