`
2277259257
  • 浏览: 498431 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

android----UI组件

 
阅读更多

 

 一、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-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-awesome-android-ui.zip,一份精选的android ui/ux库列表,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    android-02-UI基本组件及事件处理.ppt

    android-02-UI基本组件及事件处理.ppt------安卓UI基本组件intent

    Android-react-native-ui-lib.zip

    Android-react-native-ui-lib.zip,用于react native的ui组件库,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    安卓UI布局相关-android-ui各种好看的组件.rar

    android-ui各种好看的组件.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。

    Android--UI-新手必备源码master.zip

    包括Android布局,弹窗,配色,单击事件,UI,精美炫酷的activity切换动画和空间动画,是新手必备的源码,内含相关的Dome 25件。 - - 文件夹 PATH 列表 卷序列号为 4E8D-6931 C:. │ .txt │ Android-UI-新手必备...

    20.[开源][安卓][翻页效果的UI组件]android-flip-master

    20.[开源][安卓][翻页效果的UI组件]android-flip-master Aphid FlipView是一个能够实现Flipboard翻页效果的UI组件。

    Android-cardslider-android.zip

    -https://github.com/ramotion/android-ui-animation-components-and-libraries网站,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    Android UI控件组件库集合【源码】

    Android UI控件组件库集合【源码】 热门标签,流式布局,刮刮乐控件,侧滑控件,循环幻灯片控件,自动换行控件,下拉列表,圆角进度控件等常用UI控件组件合集

    android-ui-components:适用于Android项目的UI组件

    Trendyol Android团队的Android UI组件。 UI组件包含用于Android平台的多个自定义视图,以使开发人员的工作更轻松!为什么? Android应用程序,我们使用了几种自定义视图实现,这些实现可能对其他应用程序有用。组件...

    Android-react-native-shop-ui.zip

    Android-react-native-shop-ui.zip,一个反作用的本地服装购物应用程序用户界面。,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    Android-react-native-material-ui.zip

    Android-react-native-material-ui.zip,高度可定制的React Native材料设计组件,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    awesome-android-ui-master.zip

    精挑细选的优秀Android UI/UX库。这些库包含一系列预封装好的组件、工具和解决方案,旨在帮助Android开发者快速构建美观、交互友好且符合最佳实践的应用程序。

    安卓UI布局相关-AndroidUI组件库各种好看的组件.rar

    Android UI组件库,各种好看的组件.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。

    Android UI组件实例集合

    9、Android的UI工具包 android-ui-utils 是一个工具包用来帮助设计和开发 Android 用户界面,包含三个单独的工具:Android Asset Studio用户界面原型模具,Android 设计预览,时常需要重复确认程序版面设计状况的 ...

    Android-ui.zip

    Android-ui.zip,React本机应用程序的可自定义组件集,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    Android-Tweet-uiTweetMediaView组件库

    Tweet-ui TweetMediaView组件库

    Android-UIWidgets.zip

    Android-UIWidgets.zip,uiwidget是一个统一的包,它帮助开发人员创建、调试和部署高效的跨平台应用程序。,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的...

    realm-android-adapters:用于将Realm Java与Android UI组件和框架类结合的适配器

    该存储库包含用于将Realm Java与Android UI组件和框架类组合的适配器。 当前支持的UI组件是: 入门 该库仅与Realm Java一起使用。 请参阅的将Realm添加到您的项目中。 要将适配器添加到项目中,请在应用程序的...

    Android代码-通用IM UI组件

    []() []() Aurora IMUI 中文文档 Aurora IMUI is a general IM UI ...We already have Android/iOS platforms support. We also plan to support React Native. Features With Aurora IMUI, you can implement

Global site tag (gtag.js) - Google Analytics