`
jacky-zhang
  • 浏览: 319031 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Android 重用Layout Common action

 
阅读更多
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<Button android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:id="@+id/Button11"
		android:text="Activity 1"></Button>
	<Button android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:id="@+id/Button12"
		android:text=" Activity 2   "></Button>
</LinearLayout>


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:background="#ffffff"
		android:text="Activity -- 1          "></TextView>
	<RelativeLayout android:id="@+id/RelativeLayout02"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_centerInParent="true">
	</RelativeLayout>
	<com.farhan.masterLayout.Footer
		android:id="@+id/layoutFooter" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:layout_alignParentBottom="true" />
</RelativeLayout>


public class Activity1 extends Activity {

	Footer footer;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		footer = (Footer) findViewById(R.id.layoutFooter);
		footer.setActivity(this);

	}

}


public class Footer extends LinearLayout {
	private Context mContext;
	private Button btn11;
	private Button btn12;
	// use Activity Object to call finish() method which is not possible using
	// context
	private Activity mActivity;

	public Footer(Context context, AttributeSet attrs) {
		super(context, attrs);

		mContext = context;

		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li;

		li = (LayoutInflater) getContext().getSystemService(infService);
		li.inflate(R.layout.footer, this, true);

		btn11 = (Button) findViewById(R.id.Button11);
		btn11.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(mContext, Activity1.class);
				mActivity.finish();
				mActivity.startActivity(myIntent);
			}

		});

		btn12 = (Button) findViewById(R.id.Button12);
		btn12.setOnClickListener(mFooterListener);

	}

	public void setActivity(Activity activity) {
		// set init otherwise of ctor and call externally...
		mActivity = activity;
	}

	// Create an anonymous implementation of OnClickListener
	private OnClickListener mFooterListener = new OnClickListener() {
		public void onClick(View v) {
			Intent myIntent;
			switch (v.getId()) {
			case R.id.Button12:
				myIntent = new Intent(mContext, Activity2.class);
				mActivity.finish();
				mActivity.startActivity(myIntent);
				break;
			}

		}
	};
}


Here  its complete source code.http://www.megaupload.com/?d=QWCP60GN
分享到:
评论

相关推荐

    android layout 简单例子

    6. 碎片布局(Fragment Layout):虽然不是直接的布局类型,碎片在Android中用于创建可重用的UI片段,它们可以嵌入到活动中,提供更灵活的界面设计,特别是在平板设备上。 7. CoordinatorLayout:这是一种高级布局...

    Android应用:主Layout文件中包含2个Fragment

    在Android应用开发中,Fragment是构建用户界面的重要组成部分,它允许开发者在单个活动中创建可重用、可组合的UI块。本主题将深入探讨如何在一个主Layout文件中包含两个Fragment,以及如何实现这样的复合界面。 ...

    Android自定义控件:可重用的自定义Dialog类

    android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/dialog_background"&gt; android:id="@+id/tvDialogTitle" ...

    android include merge标签

    需要注意的是,`merge`标签必须作为顶级元素,并且不能包含根布局属性(如`android:layout_width`和`android:layout_height`)。此外,由于`merge`标签不会生成实际的View对象,所以它不能直接设置属性,所有属性...

    android layout布局分析与优化

    ### Android Layout布局分析与优化 #### 一、概述 在Android开发中,高效的布局设计对于提升应用性能至关重要。本文将详细介绍如何使用Hierarchy Viewer工具进行布局分析,并基于分析结果提出优化建议,帮助开发者...

    android 评论页面listview实现

    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"&gt; android:id="@+id/listViewComments" android:layout_width=...

    android入门重点讲义(含有代码).pdf

    Android 应用程序开发中,某些资源文件或 UI 组件可以被重用,以提高开发效率和减少代码冗余。例如,某个按钮的样式可以被定义在一个 XML 文件中,然后在多个活动中重用该按钮。 二、TextView 属性设置 TextView ...

    xml andriod layout

    - `android:layout_width` 和 `android:layout_height`:定义视图的宽度和高度,可设置为`match_parent`(填充父容器)、`wrap_content`(根据内容自动调整大小)或具体的像素值。 - `android:orientation`:在`...

    Android中include和merge标签的使用

    `include`和`merge`标签是Android XML布局文件中两个非常重要的元素,它们帮助开发者实现布局的重用和优化,提高代码的可维护性和效率。本篇文章将深入探讨这两个标签的使用方法以及它们在Android开发中的作用。 ##...

    android起航 Beginning Android

    例如,`android:text`属性用于设置按钮上的文本,而`android:layout_width`和`android:layout_height`则指定了组件的尺寸。 **为什么使用XML布局?** 1. **代码分离**:XML布局将界面设计与业务逻辑分开,使得代码...

    Android In Action书籍和源码SourceCode

    6. **Layout**: 布局是定义Android UI结构的方式,常见的布局有LinearLayout、RelativeLayout、ConstraintLayout等,开发者需要熟练掌握各种布局的使用以创建美观且响应式的界面。 7. **SQLite数据库**: Android...

    android列表视图实例

    android:layout_height="match_parent" /&gt; ``` 接着,我们需要创建一个表示列表项的布局文件(如 item_list.xml),例如: ```xml &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

    Layout控件(线性布局,框架布局,表格布局,相对布局,约束布局)

    在Android开发中,布局(Layout)是构建用户界面的核心组件,它们决定了屏幕上元素的排列方式和相互关系。本文将深入探讨五种主要的布局控件:线性布局(LinearLayout)、框架布局(FrameLayout)、表格布局...

    Android Activity设置相同的action进行判断源码.rar

    但开发者可以通过设置`android:launchMode`属性避免这种情况,例如使用“singleTask”或“singleTop”模式,这样只有一个Activity实例会被启动或重用。 4. **源码分析**:压缩包中的"Android Activity设置相同的...

    android_relativeLayout_demo

    - `android:layout_toLeftOf` / `android:layout_toRightOf`:使视图位于另一个视图的左边或右边。 - `android:layout_below` / `android:layout_above`:使视图位于另一个视图的下方或上方。 3. **视图之间的...

    Android Fragment简单应用

    在Android开发中,Fragment是应用程序界面的一个可重用组件,它可以在Activity中承载用户界面的各个部分。Fragment的概念引入是为了让开发者能更好地处理大屏幕设备,如平板电脑,同时也可以在手机等小屏幕设备上...

    android 10.布局(Layout)在Android软件开发上的重要角色

    布局(Layout)在Android软件开发上的重要角色”这一主题时,我们首先需要理解布局(Layout)在Android开发环境中的核心地位。布局不仅关乎界面设计的美观,更是连接用户与功能的关键桥梁,其重要性不言而喻。 ### ...

    action的三种类型

    与非重用型Action不同,重用型Action可以在同一个测试中多次调用,也可以被其他测试所引用。这种类型的Action极大地提高了代码的复用率,降低了后期维护的工作量: - **重用机制**:通过将常见或复杂的操作封装为...

    Android listview使用的简单事例

    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; android:id="@android:id/list" android:layout_width="match_parent" android:layout_...

    android利用fragment实现TabActivityd的效果

    在Android应用开发中,Fragment是Android SDK 3.0(API级别11)引入的一个重要组件,用于构建可重用的、模块化的用户界面部分。TabActivity曾是Android早期版本中实现标签页切换的主要方式,但随着Android API的发展...

Global site tag (gtag.js) - Google Analytics