android中扩展View类的背景设置
2015-09-23 17:22
399 查看
既然是继承View的 可以在XML布局里面直接设置背景。 <com.android.widget.MyView android:id="@+id/myview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/background" //设置背景 android:layout_marginTop="11px" android:layout_marginLeft="506px"/> 如果想在代码里面设置背景,结合上面的XML文件: private MyView mView; mView = (MyView) findViewById(R.id.myview); mView.setBackgroundResource(R.drawable.background); 如果想在自定义控件的代码中直接设置背景,需要先在构造函数中获取背景图片,然后在 onDraw中画背景图片。 mBackGround = ((BitmapDrawable) this.getResources().getDrawable(R.drawable.background)).getBitmap(); //获取背景图片 Paint mPaint = new Paint(); canvas.drawBitmap(mBackGround, 0, 0, mPaint); //画背景图片
相关文章推荐
- android 应用程序入口
- Android 获取ROOT权限原理解析
- 【Android开源项目解析】RecyclerView侧滑删除粒子效果实现——初探Android开源粒子库 Leonids
- Android SDK开发包国内下载地址
- Android Studio + NDK 之 Hello Word
- Android版本和API Level对应关系
- android编译时Failure [INSTALL_FAILED_OLDER_SDK]
- Android Studio常用的40个快捷键
- 【MDCC技术大咖秀】Android内存优化之OOM
- Android Studio快捷键设置
- Android视频分享-初学者你必须知道的那些事儿
- 16.Android Activity的launchMode
- Android 高德地图标记一组Marker,并有点击事件(上)
- Android绘图总结
- android Imageview setBackgroundResource 背景闪一下就消失了
- Android实现新浪微博和QQ登陆并获取用户的信息
- 构建超过65535方法数的安卓程序
- Android 蓝牙开发(二)开启蓝牙,获取状态,发现设备。
- Android快捷开关实现(转)
- Android读写文件操作