android自定义控件介绍
由于android的高度开放性,我们可以定制各种各样的控件来满足自己的需求,本专栏将介绍如果写一些定制的自定义控件
移动爱好者
这个作者很懒,什么都没留下…
展开
-
android如何写一个循环文字滚动的TextView
我们来看这样一个Text("如何在TextView中插入表情符号如(#f1),邮件[email protected],电话号码18559298168呢,默认的TextView是支持不了这个特性的"),我们如何把里面的表情标签,电话号码等提取出来的,这个我可以用正则表达式可以实现:private static Pattern EMAIL_PATTERN = Patterns.EMAIL_A...原创 2014-08-10 16:34:21 · 5904 阅读 · 0 评论 -
android如果重写onDraw实现一个类似TextView可以显示表情和链接的控件(二)
下面来写IntroView的onMeasureHeight:private int measureHeight(int measureSpec) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize原创 2014-08-10 15:32:13 · 1631 阅读 · 0 评论 -
android如果重写onDraw实现一个类似TextView可以显示表情和链接的控件(一)
先看效果图:写一个超连接支持的对象:/**作为超连接显示的对象*/public class LinkInfo implements Comparable{ private String content; private String type; private String id; private boolean bIsFace = false;原创 2014-08-10 15:21:19 · 1709 阅读 · 0 评论 -
android一个上传图片的例子,包括如何终止上传过程,如果在上传的时候更新进度条(二)
可以这样来实现上传:activity中执行: private class UploadPhotoTask extends AsyncTask{ @Override protected void onPreExecute() { super.onPreExecute(); } protected Boolean doInBackground(String.原创 2014-08-10 09:19:26 · 2365 阅读 · 0 评论 -
如果写一个android桌面滑动切换屏幕的控件(三)
下面我们把这个控件内嵌到Layout中做一些动画和展示,效果图:这个子控件可以上下移动,可以左右滑动,如果上下滑动距离大于左右滑动距离,则必须上下滑动这样来写onTouch事件: @Override public boolean onTouchEvent(MotionEvent ev) { if (mVelocityTracker == null) { m原创 2014-08-08 20:04:32 · 1549 阅读 · 1 评论 -
如果写一个android桌面滑动切换屏幕的控件(二)
在viewgroup执行:public void snapToScreen(int whichScreen) { whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); boolean changingScreens = whichScreen != mCurrentScreen; mNext原创 2014-08-08 19:15:00 · 1434 阅读 · 0 评论 -
如果写一个android桌面滑动切换屏幕的控件(一)
首先这个控件应该是继承ViewGroup:初始化:public class MyGroup extends ViewGroup{ private Scroller mScroller; private float mOriMotionX; private float mLastMotionX; private VelocityTracker mVelocityTracker;原创 2014-08-08 17:45:42 · 1748 阅读 · 0 评论 -
android一个弹出菜单的动画(一)
先上效果图:先写Layout文件:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_paren原创 2014-08-06 17:53:18 · 2756 阅读 · 1 评论 -
android一个弹出菜单的动画(二)
如果做一个弹出的控件,我们可以进行添加view:写class SatelliteMenu extends FrameLayoutprivate void init(Context context, AttributeSet attrs, int defStyle) { inflate(context, R.layout.sat_main, this); imgMain = (Ima原创 2014-08-08 16:34:43 · 1709 阅读 · 0 评论 -
android如何写一个投票或是表达观点的界面
先上图:把这些表示观点的view放在一个LinearLayout里:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/repost_vote_tag_list" android:l原创 2014-08-04 07:07:38 · 3251 阅读 · 0 评论 -
如果写一个列表点击一张图片来preview这张图片
可以才用继承AlertDialog的形式来写:点击张图:public void onClick(View v) { viewBigsizeBmp(((ImageView) v).getDrawable(), Constants.PREVIEW_BMP_DIR_SUFFIX); } private void viewBigsizeBmp(Drawable drawable,原创 2014-08-01 22:47:25 · 1181 阅读 · 0 评论 -
android TabHost的一种用RadioButton来实现的切换
Layout:<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLa原创 2014-08-01 22:08:24 · 1113 阅读 · 0 评论 -
android如果用ListView做一个表格形式
效果图:这样来写:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); ListView list = (ListView)findViewById(R.i原创 2014-08-01 20:33:56 · 3514 阅读 · 1 评论 -
android的ViewPager和Animation的一些使用(二)
Animation的部分android的animation分为scale,rotate,tranlateAnimation,alpha这几种start animation的方式以下几种: t1_icon1.setImageResource(R.drawable.t1_frame_animation); //t1_frame_animation这个动画是放在drawab原创 2014-07-15 11:20:20 · 1556 阅读 · 2 评论 -
android的ViewPager和Animation的一些使用(一)
android的ViewPager是一个可以支持手势来切换View的控件,很适合来做用户引导的页面:如果有4张图,那么我们这样来写Layout:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/whats_new_main_view" andr原创 2014-07-15 10:54:21 · 1941 阅读 · 0 评论 -
android如何在textview或edittext上添加表情
先上效果图:首先来写一个表情的GridViewpublic class EmotionView extends LinearLayout implements OnItemClickListener { private GridView mGridView; private static final ArrayList emotionDisplayList = new原创 2014-07-31 06:53:21 · 4249 阅读 · 1 评论 -
AlertDialog自定义View的用法+如何改变弹出框的大小
android系统定义了弹出框,支持我们自定义布局: public AlertDialog getEditCustomDialog() { LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.custom_message_rename, null); AlertDi原创 2014-07-11 11:59:42 · 8880 阅读 · 0 评论 -
如果做一个精美的Login界面(解决了一EditText自带clear的功能,类似iphone的UITextField)
先上图: XML为:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:la原创 2014-07-10 13:55:50 · 2593 阅读 · 0 评论 -
android Title滑块动画实现(适合新闻客户端多种栏目的展示)
先上效果图,选择不同的模块,滑动会通过动画形式滑过去,这种适合新闻客户端多种栏目的展示:这么写Layout:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="原创 2014-07-01 13:20:43 · 2975 阅读 · 15 评论 -
自定义TextView解决超长文字显示的问题
很多时候由于手机屏幕的显示,TextView原创 2014-06-19 13:12:53 · 3673 阅读 · 1 评论