ITeye博客

android

共 18 篇文章

设置属性自定义Item

public class Item extends RelativeLayout { private TextView tvTitle; private TextView tvValue; public Item(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.item); String title = a.getString(R.styleable.item_item_title); S…

2016-03-08 01:30 · android

MappedByteBuffer读取大文件

RandomAccessFile randomAccessFile = new RandomAccessFile(file,"rw"); FileChannel fileChannel = randomAccessFile.getChannel(); long size = fileChannel.size(); MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE,0,size); for ( int i = 0 ; i < size; i++){ byte b = mapped…

2016-03-08 01:29 · android

自定义ImageView

图片等比例缩放,从0.0左边开始剪切 保证图片不变形 /** * @Description * @Created by YCH on 2015/11/9. */ public class CropImageView extends ImageView { /** * 画布的宽度 */ private int width; /** * 画布的高度 */ private int height; float scaleWidth = 1.0f; float scaleHeight = 1.0f; public CropImageView(Context context) { super(conte…

2016-03-08 01:29 · android

TextView跳转到网页

private String url = "<a>https://www.baidu.com</a>"; textView.setText(Html.fromHtml(url)); <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:autoLink="all" />

2016-03-08 01:29 · android

textView的背景为白色的时候 需要加重影

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_…

2016-03-04 11:56 · android

AndroidEventBus基本使用

Android中的Activity, Fragment, Service之间的交互是比较麻烦的,可能我们第一想到的是使用广播接收器来在它们之间进行交互。 例如上述所说在Activity-B中发一个广播,在Activity-A中注册一个广播接收器来接受该广播。但使用广播接收器稍显麻烦,如果你 要将一个实体类当做数据在组件之间传递,那么该实体类还得实现序列化接口,这个成本实在有点高啊! 1.使用AndroidEventBus首先需要在onCreate中注册 EventBus.getDefault().register(Object obj); 同时需要在OnDestory中取消 EventBus…

2016-03-04 11:56 · android

利用ValueAnimator实现CountDownTimer效果

btn_code.setClickable(false); ValueAnimator valueAnimator = ValueAnimator.ofInt(59,0); valueAnimator.setDuration(59 * 1000); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Integer value = (Integer) anim…

2015-11-23 19:17 · android

android在线更新提示安装成功

废话不多说 直接贴代码 Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(i); android.os.Process.killProcess(android.os.Process.myPid());

2015-08-11 14:13 · android

RecyclerView入门

android studio 1.2.1.1 首先配置下v7的库 dependencies { compile 'com.android.support:recyclerview-v7:22.2.0' } public class RecyclerViewActivity extends Activity { private RecyclerView recycler; private RecyclerView.LayoutManager mLayoutManager; private List<HashMap<String,Object>> data; @Override protecte…

2015-07-17 14:47 · android

Gallery之无限循环

其实这个很简单的,如果你接触过ViewPager那么这个功能分分钟就实现了. 布局文件就不贴出来了,就是一个简单的Gallery /** * Created by Y on 2015/7/16. * Gallery无限循环 */ public class GalleryActivity extends Activity{ private Gallery gallery; //图片源数组 private Integer[] imageInteger={ R.drawable.ic_launcher, R.drawable.logo_twitter, R.drawable.logo_vkonta…

2015-07-16 17:21 · android

Gallery入门

最近项目不是很忙,就研究点平时没有接接触过的控件,直接上代码,效果图附件,界面有点丑 /** * Created by Y on 2015/7/16. */ public class GalleryActivity extends Activity implements ViewSwitcher.ViewFactory{ private Gallery gallery; private ImageSwitcher imageSwitcher; //图片源数组 private Integer[] imageInteger={ R.drawable.ic_launcher, R.drawable…

2015-07-16 17:09 · android

使用app打开ppt/doc等文件

//android获取一个用于打开PPT文件的intent Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); //and…

2015-06-11 15:56 · android

二维码生成与解析

private void createImage() { try { // 需要引入core包 QRCodeWriter writer = new QRCodeWriter(); // 把输入的文本转为二维码 BitMatrix martix = writer.encode(info, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT); System.out.println("w:" + martix.getWidth() + "h:" + martix.getHeight()); Hashtable<EncodeHintType, String> hi…

2015-05-13 11:24 · android

一个小项目自定义editText

public class MyEditText extends EditText{ private Context mContext; private Drawable drawable; private Drawable bgDrawable; public MyEditText(Context context) { super(context); mContext = context; init(); } public MyEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs,…

2015-05-12 15:51 · android

textView自动滑动

今天一个功能需要用到textview滑动效果,在网上找了几个例子 整理一下,以备后用 <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:sing…

2015-04-17 12:51 · android

圆形图标

public class CircleImageView extends ImageView { private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; private static final int COLORDRAWABLE_DIMENSION = 1; private static final int DEFAULT_BORDER_WIDTH = 0; pr…

2015-04-15 09:38 · android

notification功能实现

NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(); notification.icon = R.drawable.icon; notification.tickerText = "我在这里"; // notification.defaults = Notification.DEFAULT_SOUND; // notification.audi…

2015-04-08 13:57 · android

仿微信二维码生成以及条形码生成(转)

package your.QRCode.namespace; import java.io.File; import java.io.FileOutputStream; import java.util.HashMap; import java.util.Map; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.WriterException; imp…

2014-02-13 10:56 · android