一、android自带的UI组件
android中-UI组件实例大全:http://blog.csdn.net/column/details/ui-demo.html
二、自定义UI组件
android中-自定义组件和属性:
Android系统虽然自带了很多的组件,但肯定满足我们个性化的需求,所以我们为了开发方便,需要自定义Android的UI组件,以实现我们个性化的需求
自定义组合控件的步骤:
1 、自定一个View,需要继承相对布局,线性布局等ViewGroup的子类。ViewGroup是一个其他控件的容器,能够乘放各种组件。
2 、实现父类的3个构造方法。一般需要在构造方法里始化初自定义布局文件。
一个参数构造方法:为new控件使用
两个参数的造方法:在调用布局文件使用
三个参数的造方法:传递带有样式的布局文件使用
3 、根据需求,定义一些API方法
4 、根据需要自定义控件的属性。可以参考TextView的属性写
5 、自定义命名空间:
xmlns:xxx="http://schemas.android.com/apk/res/<包名>" xxx为为scheam名
6 、自定义我们的属性, 在res/values/attrs.xml(创建属性文件)定义属性
7 、使用自定义的属性:
例如:
andy:desc_off="设置自动更新已经关闭"
andy:desc_on="设置自动更新已经开启"
andy:titles="设置自动更新"
8 、在我们自定义控件的带两个参数的构造方法里面,AttributeSet attrs取出自定属性值,关联到自定义布局文件对应的控件
1 定义一个自定义控件:setting_item_view.xml布局文件
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="68dip"> <textview android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dip" android:layout_margintop="8dip" android:text="设置是否自动更新" android:textcolor="#000000" android:textsize="20sp"> <textview android:id="@+id/tv_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv_title" android:layout_marginleft="10dip" android:text="自动更新已经关闭" android:textcolor="#88000000" android:textsize="18sp"> <checkbox android:id="@+id/cb_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="10dip"> <view android:clickable="false" android:layout_width="match_parent" android:layout_height="0.2dip" android:layout_alignparentbottom="true" android:layout_marginleft="5dip" android:layout_marginright="5dip" android:background="#000000"> </view></checkbox></textview></textview></relativelayout>
2 在对应的Activity布局文件中调用
<!--?xml version="1.0" encoding="utf-8"?--> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:andy="http://schemas.android.com/apk/res/com.andy.mobilesafe" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.andy.mobilesafe.ui.settingitemview android:id="@+id/siv_update" android:layout_width="wrap_content" android:layout_height="wrap_content" andy:desc_off="设置自动更新已经关闭" andy:desc_on="设置自动更新已经开启" andy:titles="设置自动更新"> </com.andy.mobilesafe.ui.settingitemview></linearlayout>
3 自定义属性:res/values/attrs.xml
<!--?xml version="1.0" encoding="utf-8"?--> <resources> <declare-styleable name="TextView"> <!-- 自定义控件的属性 --> </attr></attr></attr></declare-styleable> </resources>
4 实现自定义组件,继承ViewGroup的子类,实现构造方法,和对应的API方法
package com.andy.mobilesafe.ui; import com.andy.mobilesafe.R; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.CheckBox; import android.widget.RelativeLayout; import android.widget.TextView; /** * @author Zhang,Tianyou * @version 2014年11月15日 下午10:22:50 * * 自定义组合控件 两个TextView 一个checkbox 一个View */ public class SettingItemView extends RelativeLayout { private CheckBox cb_status; private TextView tv_title; private TextView tv_desc; private String desc_on; private String desc_off; /** * 初始化布局文件 * * @param context */ private void initView(Context context) { // 第二个为布局文件 root第三个参数为布局文件父类 // 把一个布局文件 View 并加载在SettingItemView View.inflate(context, R.layout.setting_item_view, this); // View 已经加载该SettingItemView cb_status = (CheckBox) this.findViewById(R.id.cb_status); tv_desc = (TextView) this.findViewById(R.id.tv_desc); tv_title = (TextView) this.findViewById(R.id.title); } public SettingItemView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // 这个是可以传递一个样式 调用 initView(context); } /** * 带有两个参数的构造方法 ,布局文件使用的时间调用 * * @param context * @param attrs * 得到属性值 */ public SettingItemView(Context context, AttributeSet attrs) { super(context, attrs); // 自定义布局使用调用的构造方法 attrs为配置的属性 布局文件中使用 initView(context); String titles = attrs.getAttributeValue( "http://schemas.android.com/apk/res/com.andy.mobilesafe", "titles"); desc_off = attrs.getAttributeValue( "http://schemas.android.com/apk/res/com.andy.mobilesafe", "desc_off"); desc_on = attrs.getAttributeValue( "http://schemas.android.com/apk/res/com.andy.mobilesafe", "desc_on"); tv_title.setText(titles); setDesc(desc_off); } public SettingItemView(Context context) { super(context); // new 出的时间使用 initView(context); } /** * 校验组合控件是否有选中 * * @return */ public boolean isChecked() { return cb_status.isChecked(); } /** * 设置组合控件选中 * * @param checked */ public void setChecked(boolean checked) { if(checked){ setDesc(desc_on); }else { setDesc(desc_off); } cb_status.setChecked(checked); } /** * 设置组合控件的描述信息 * * @param text */ public void setDesc(String text) { tv_desc.setText(text); } }
三、引用第三方开源的UI组件库
http://www.oschina.net/project/tag/342/
相关推荐
Android-android-ui-animation-components-and-libraries.zip,android ui库、组件和动画作者@ramotion-https://github.com/ramotion/swift-ui-animation-components-libraries,安卓系统是谷歌在2008年设计和制造的。...
Android-awesome-android-ui.zip,一份精选的android ui/ux库列表,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
三、`android-ui-test-runner`核心组件 1. **Test Runner**:`android-ui-test-runner`中的Test Runner是自定义的JUnit测试运行器,它扩展了`android.support.test.runner.AndroidJUnitRunner`,添加了额外的功能,...
Fragment则是在Activity中嵌套的可重用的UI组件,它们可以在多个Activity之间共享,有助于创建灵活的布局。 3. **布局管理器**:Android提供了多种布局管理器,如LinearLayout、RelativeLayout、GridLayout和...
2. **片段(Fragment)**:Fragment是Android UI设计中的一个可重用组件,可以在多个Activity之间共享,使得在不同屏幕尺寸和配置上构建适应性强的用户界面成为可能。 3. **MVP(Model-View-Presenter)模式**:MVP...
标题提到的"android-support-v4 .jar"和"android-support-annotations.jar"是Android支持库中的两个关键组件。 "android-support-v4 .jar"是Android支持库的v4版本,它是对Android API Level 4(Android 1.6 Donut...
Android SDK(Software Development Kit)是开发Android应用必不可少的工具集,它包含了编译、调试、模拟器、性能分析等一系列开发者需要的组件。Android-26指的是Android 8.0 Oreo版本,这是Google在2017年发布的一...
android-02-UI基本组件及事件处理.ppt------安卓UI基本组件intent
Android-react-native-ui-lib.zip,用于react native的ui组件库,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
ActionBar是Android 3.0引入的一个重要的UI元素,它提供了应用的导航和操作选项。在早期版本的Android系统中,没有内置的ActionBar,因此`android-support-v7-appcompat`库通过自定义视图和主题实现了对ActionBar的...
Fragment是Android应用程序设计的一个关键组件,它允许你在单个Activity中创建多个独立的UI片段。Loader则是一种异步加载数据的机制,能够有效地处理数据加载与界面交互。IntentCompat则提供了对Intent的一些兼容性...
在这里,我们可以找到一系列的示例代码和应用程序,帮助开发者理解和学习如何有效地利用Android的UI组件。 在深入探讨之前,先了解一下Android UI Toolkit。它是Android SDK的一部分,提供了一系列用于构建用户界面...
"ui-fabric-android"是一个专为Office和Office 365设计的前端框架,它针对Android平台进行了优化,旨在提供一致、高效的用户界面组件,帮助开发者构建与Microsoft Office风格一致的应用体验。这个开源项目允许开发者...
Android Support Library v4是一个重要的组件,它为Android应用程序提供了向后兼容的功能。这个库使得开发者能够使用最新的API特性,即使目标设备运行的是早期版本的Android系统。`android-support-v4.jar`是这个库...
这些特性使得`RecyclerView`成为处理大量数据并实现动态UI效果的首选组件。 在实际项目中,`android-support-v7`库的`AppCompatActivity`和`android-support-v7-recyclerview`库的`RecyclerView`通常一起使用。例如...
在Android开发领域,UI设计是至关重要的一环,它直接影响到应用程序的用户体验和视觉吸引力。"Android-UI-Tutorials-master"这个压缩包显然包含了与Android用户界面相关的教程和示例代码,旨在帮助开发者学习和掌握...
Fragment是Android开发中重要的模块化组件,允许开发者将UI拆分为可重用的部分,即使在较小的屏幕上也能保持良好的用户体验。Loader则帮助管理数据加载,避免在配置更改时丢失数据。View Pager用于创建滑动页面效果...
7. **测试支持**:Android Studio提供了JUnit和Espresso等测试框架,支持单元测试和UI测试,确保应用的功能完整性和稳定性。 8. **Kotlin优先**:自Android Studio 3.0版本起,Kotlin成为首选的编程语言。Kotlin以...
首先,`android-support-v7-appcompat.jar` 是Android Support Library的一个组件,主要用于提供对Android 2.1(API级别7)及更高版本的向后兼容。这个库主要包含一个关键组件:ActionBar。在Android 3.0(API级别11...
总之,`android-support-v7-appcompat.jar`和`android-support-v4.jar`是Android开发中的重要工具,它们帮助开发者实现跨版本兼容,使用新的API特性,并提供了丰富的UI组件。理解和熟练运用这两个库,是提升Android...