实际开发android 自定义vue 覆盖组件中的样式和自定义样式用的多么

1,224被浏览56,401分享邀请回答48672 条评论分享收藏感谢收起2D绘图基本要素
Bitmap,BitmapFactory,BitmapRegionDecoder,ImageFormat,Movie,NinePatch
Xfermode 主要子类 PoterDuffXfermode
RGB过滤 ColorFilter的三个子类 ColorMatrixFilter, PoterDuffColorFilter, LightingColorFilter
alpha过滤 MaskFilter的两个实现类 BlurMaskFiler, EmbossMaskFilter
DrawFilter的实现 PaintFlagsDrawFilter
ColorMAtrix
Shader的五个实现 BitmapShader, LinearGradient, SweepGradient, RadialGradient, ComposeShader
PathEffect
PathMeasure
Rasterizer
Drawable系列
BitmapDrawable,ShapeDrawable,LayerDrawable等等
这些API这么多,你没有必要一个个看完,心中有个大概每个能做什么就行;然后我举个简单的例子:当时有一个webview界面要做一个loading动画,不是进度条也不是点点点的那种,而是一个小人在跑步,很常见吧。一般的情况下弄一个帧动画就完事了,但是这里有个很蛋疼的事情:我们发现在有的手机上面,这个loading比一般的时候长,而且基本都是高端机,没有loading秒开,有了loading要等好几秒。原因很明显,罪魁祸首在这个loading,动画的执行是在主线程的,而webview的一些事件调度也是在主线程的,很有可能是这个动画阻碍了这个webview某些事件的执行,从而导致加载变慢。最终决定用SurfaceView解决:你不是不想在主线程刷新界面么,好,我单独给你开个线程专门执行动画;这个SurfaceView只给了你一个Canvas怎么办?每隔16ms draw一下界面,然后用Canvas.drawBitmap把小人画上去,然后隔一定的时机绘制下一个小人形态;这个自定义View就搞定了。最终loading流畅无比,完美解决问题。这就是一个非常简单的自定义View,没有处理layout,wrap_content等各种问题,但是你应该能感受到,自定义View不是什么神秘的事情。2. 动态假设你的自定View写好了,那么用户点击和滑动的时候会发生什么?如何处理点击事件和滑动事件?嵌套ScrollView会不会卡?喂猫点击某个View没反应?为什么在listView里面放button和imageView点击反应有区别?这些问题归根结底,是View事件传递的问题;所以你得学习Android View的事件分发机制,相关教程网上非常之多,《艺术探索》和《群英传》都有讲,不赘述。另外,可能有一些View还有动画,这就是另外一个话题了;酷炫的动画也是一个漂亮的App必不可少的内容,篇幅所限,略。最后,我依然想强调一点:最重要的是自己动手!最重要的是自己动手!你就算把我列的那些东西全学完了,书全看完了,API和ApiDemos也全都看过了;自己不真正写一个出来那就是扯淡,也浪费我扯这么多的时间。1466 条评论分享收藏感谢收起实际开发android 自定义组件和自定义样式用的多么_百度知道
实际开发android 自定义组件和自定义样式用的多么
我有更好的答案
看你的需要咯。你要是有特殊需要就可以自己写一个自定义组件啊
采纳率:74%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)Android开发之自定义控件用法详解
转载 & & 作者:wop_niaoren
这篇文章主要介绍了Android开发之自定义控件用法,结合实例形式分析了Android自定义控件的具体功能、定义与使用方法,需要的朋友可以参考下
本文实例讲述了Android开发之自定义控件用法。分享给大家供大家参考,具体如下:
今天和大家分享下组合控件的使用。很多时候android自定义控件并不能满足需求,如何做呢?很多方法,可以自己绘制一个,可以通过继承基础控件来重写某些环节,当然也可以将控件组合成一个新控件,这也是最方便的一个方法。今天就来介绍下如何使用组合控件,将通过两个实例来介绍。
第一个实现一个带图片和文字的按钮,如图所示:
整个过程可以分四步走。第一步,定义一个layout,实现按钮内部的布局。代码如下:
custom_button.xml
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android=http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingBottom="10.0dip"
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_marginLeft="8dip"
android:layout_gravity="center_vertical"
android:paddingLeft="5.0dip"
android:paddingTop="10.0dip"
android:paddingBottom="10.0dip"
android:paddingRight="10.0dip"
android:textSize="18.0sp"
&/LinearLayout&
这个xml实现一个左图右字的布局,接下来写一个类继承LinearLayout,导入刚刚的布局,并且设置需要的方法,从而使的能在代码中控制这个自定义控件内容的显示。代码如下:
CustomButton.java
package com.szy.
import android.content.C
import android.util.AttributeS
import android.view.LayoutI
import android.widget.ImageV
import android.widget.LinearL
import android.widget.TextV
public class CustomButton extends LinearLayout
private ImageV
private TextV
public CustomButton(Context context)
this(context, null);
public CustomButton(Context context, AttributeSet attrs)
super(context, attrs);
// 导入布局
LayoutInflater.from(context).inflate(R.layout.custom_button, this, true);
iv = (ImageView) findViewById(R.id.iv);
tv = (TextView) findViewById(R.id.tv);
* 设置图片资源
public void setImageResource(int resId)
iv.setImageResource(resId);
* 设置显示的文字
public void setTextViewText(String text)
tv.setText(text);
第三步,在需要使用这个自定义控件的layout中加入这控件,只需要在xml中加入即可。方法如下:
&LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
&com.szy.customview.CustomButton
android:id="@+id/bt_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
&com.szy.customview.CustomButton
android:id="@+id/bt_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
&/LinearLayout&
注意的是,控件标签使用完整的类名即可。为了给按钮一个点击效果,你需要给他一个selector背景,这里就不说了。
最后一步,即在activity中设置该控件的内容。当然,在xml中也可以设置,但是只能设置一个,当我们需要两次使用这样的控件,并且显示内容不同时就不行了。在activity中设置也非常简单,我们在CustomButton这个类中已经写好了相应的方法,简单调用即可。代码如下:
package com.szy.
import android.app.A
import android.os.B
import android.view.V
import android.view.View.OnClickL
public class MainActivity extends Activity
private CustomButton btnC
private CustomButton btnC
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnConfirm = (CustomButton) findViewById(R.id.bt_confirm);
btnCancel = (CustomButton) findViewById(R.id.bt_cancel);
btnConfirm.setTextViewText("确定");
btnConfirm.setImageResource(R.drawable.confirm);
btnCancel.setTextViewText("取消");
btnCancel.setImageResource(R.drawable.cancel);
btnConfirm.setOnClickListener(new OnClickListener()
public void onClick(View v)
// 在这里可以实现点击事件
这样,一个带文字和图片的组合按钮控件就完成了。这样梳理一下,使用还是非常简单的。组合控件能做的事还非常多,主要是在类似上例中的CustomButton类中写好要使用的方法即可。
再来看一个组合控件,带删除按钮的EidtText。即在用户输入后,会出现删除按钮,点击即可取消用户输入。
定义方法和上例一样。首先写一个自定义控件的布局:
custom_editview.xml:
&?xml version="1.0" encoding="utf-8"?&
&RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
&ImageButton
android:id="@+id/ib"
android:visibility="gone"
android:src="@drawable/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#"
android:layout_alignRight="@+id/et" /&
&/RelativeLayout&
实现输入框右侧带按钮效果,注意将按钮隐藏。然后写一个CustomEditView类,实现删除用户输入功能。这里用到了TextWatch这个接口,监听输入框中的文字变化。使用也很简单,实现他的三个方法即可。看代码:
CustomEditView.java
package com.szy.
import android.content.C
import android.text.E
import android.text.TextW
import android.util.AttributeS
import android.view.LayoutI
import android.view.V
import android.widget.EditT
import android.widget.ImageB
import android.widget.LinearL
public class CustomEditView extends LinearLayout implements EdtInterface
public CustomEditView(Context context)
super(context);
public CustomEditView(Context context, AttributeSet attrs)
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.custom_editview, this, true);
private void init()
ib = (ImageButton) findViewById(R.id.ib);
et = (EditText) findViewById(R.id.et);
et.addTextChangedListener(tw);// 为输入框绑定一个监听文字变化的监听器
// 添加按钮点击事件
ib.setOnClickListener(new OnClickListener()
public void onClick(View v)
hideBtn();// 隐藏按钮
et.setText("");// 设置输入框内容为空
// 当输入框状态改变时,会调用相应的方法
TextWatcher tw = new TextWatcher()
public void onTextChanged(CharSequence s, int start, int before, int count)
// TODO Auto-generated method stub
public void beforeTextChanged(CharSequence s, int start, int count, int after)
// TODO Auto-generated method stub
// 在文字改变后调用
public void afterTextChanged(Editable s)
if (s.length() == 0)
hideBtn();// 隐藏按钮
showBtn();// 显示按钮
public void hideBtn()
// 设置按钮不可见
if (ib.isShown())
ib.setVisibility(View.GONE);
public void showBtn()
// 设置按钮可见
if (!ib.isShown())
ib.setVisibility(View.VISIBLE);
interface EdtInterface
public void hideBtn();
public void showBtn();
在TextWatch接口的afterTextChanged方法中对文字进行判断,若长度为0,就隐藏按钮,否则,显示按钮。
另外,实现ImageButton(即那个叉)的点击事件,删除输入框中的内容,并隐藏按钮。
后面两步的实现就是加入到实际布局中:
&LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
&com.szy.customview.CustomEditView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
&/LinearLayout&
最后显示效果如图:
更多关于Android相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 vue改变组件style样式 的文章

 

随机推荐