博采众长,精于一技。Live for love, work for dream.

[Android开发]自定义CheckBox

在Android开发中,系统自带的默认CheckBox由于比较简陋,可能难以满足部分人的审美需求,不过,Android具有很强的扩展性,自定义CheckBox其实也很简单。
1. Layout中定义CheckBox
<CheckBox android:textSize="14.0sp" android:id="@id/my_checkbox" android:background="@null"  android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/cb_selector" android:text="自定义CheckBox" />

2. 然后定义cb_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:drawable="@drawable/cb_unchecked" />
    <item android:state_checked="true" android:drawable="@drawable/cb_checked" />
</selector>

这里需要自定义两张图片,cb_unchecked.png 和 cb_checked.png分别代表未选中和选中状态。

[Android开发]进度条对话框

在Android开发中,要做一些Loading的提示,这就需要用到进度条对话框(ProgressDialog),Android ProgressDialog继承于AlertDialog,实现方式有两种。先上图,有图有真相。
效果一:
Android ProgressDialog
效果二:
Android ProgressDialog

效果一实现代码:
ProgressDialog MyDialog = ProgressDialog.show( MyActivity.this, " " , " Loading. Please wait ... ", true);

效果二实现代码:
ProgressDialog pbarDialog;
pbarDialog = new ProgressDialog( mContext );
pbarDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pbarDialog.setMessage("Loading...");
pbarDialog.setCancelable(false);

[Android开发]ScrollView嵌套GridView的解决办法

前些日子在开发中用到了需要ScrollView嵌套GridView的情况,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即GridView会显示不全。

解决办法,自定义一个GridView控件

public class MyGridView extends GridView {
    public MyGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyGridView(Context context) {
        super(context);
    }

    public MyGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

该自定义控件只是重写了GridView的onMeasure方法,使其不会出现滚动条,ScrollView嵌套ListView也是同样的道理,不再赘述。

XML布局代码
<ScrollView android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:id="@+id/scroll_content">
        <com.yourclass.MyGridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/grid_view" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:numColumns="auto_fit"
            android:horizontalSpacing="1dip" android:verticalSpacing="1dip"
            android:columnWidth="150dip" android:stretchMode="columnWidth"
            android:gravity="center">
            
        </com.yourclass.MyGridView>
    </ScrollView>

Java调用代码
MyGridView gridview = (MyGridView) findViewById(R.id.grid_view);
gridview.setAdapter(new ImageAdapter(this));

五个最佳的Hadoop项目

1.Cascading:Cascading是基于Hadoop集群之上的数据处理API。它通过实现了丰富的功能化API,使你不需要接触MapReduce任务就能使用分布式计算能力,其核心概念是基于管道和流的数据处理。
2.Mahout:Mahout是一个基于Hadoop实现各种机器学习与数据挖掘算法库。被用来提供推荐服务。
3.Hive:Hive由Facebook出品,它为Hadoop提供了一种类似于SQL的操作接口。
4.Avro:Avro是一个基于二进制数据传输高性能的中间件。Avro通过将数据进行序列化,以使得大批量数据交互过程更方便。
5.Storm:Storm由BackType Technology出口,其口号是“实时的Hadoop系统”。

[Android]在OnCreate()中播放Animation动画

默认情况下,不能在OnCreate()中执行animation.start();是无效的,因为在OnCreate()中AnimationDrawable还没有完全的与ImageView绑定,在OnCreate()中启动动画,就只能看到第一张图片。
要实现OnCreate()加载完立即播放动画怎么办呢?解决办法是,用Handler。
package info.rebill.animation;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class Main extends Activity {
    private ImageView btnPlay;
    private AnimationDrawable playAnim;
    private Handler handler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnPlay = (ImageView) findViewById(R.id.btn_play);
        handler.postDelayed(new Runnable() {
            public void run() {
                playAnim = (AnimationDrawable) btnPlay.getBackground();
                playAnim.start();
            }
        }, 50);
    }
}

返回顶部