阅读更多

在开发Android过程中,有时已有的Loyout布局不能完全满足设计需求,这时需要在已有的Layout基础上上进行扩展,以达到通过配置文件描述布局的设计原则。

首先第一一个布局类,重写其onDraw方法。

public static class iRelativeLayout extends RelativeLayout{private PaintmPaint;private RectmRect;public iRelativeLayout( Context context, AttributeSet attrs ) {super(context, attrs);mRect = new Rect();mPaint = new Paint();mPaint.setStyle(Paint.Style.FILL_AND_STROKE);mPaint.setColor(0xFFCBD2D8);}@Overrideprotected void onDraw(Canvas canvas){super.onDraw(canvas);canvas.drawColor(0xFFC5CCD4);this.getDrawingRect(mRect);for (int i = 0; i < mRect.right; i += 7){canvas.drawRect(mRect.left + i, mRect.top, mRect.left + i + 2,mRect.bottom, mPaint);}}}

 其次,在布局配置文件中引用:

<?xml version="1.0" encoding="utf-8"?>

 

class="iRelativeLayout"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background = "#C5CCD4FF"

>

android:id = "@+id/TabLayout_One"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:layout_above = "@+id/Tabs"

>

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:visibility = "visible"

>

android:id = "@+id/ButtonOne"

android:layout_width = "wrap_content"

android:layout_height = "fill_parent"

android:text = "h3h3h3"

/>

android:id = "@+id/ButtonTwo"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:text = "11222"

android:layout_below ="@+id/ButtonOne"

/>

android:id = "@+id/ButtonThree"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:text = "wass"

android:layout_below ="@+id/ButtonTwo"

/>

最后,和其他布局一样使用即可。

更多相关文章

  1. Android:控件布局(单帧布局)FrameLayout
  2. Android(13)——RecyclerView列表流行控件,Glide图片流行框架
  3. 居中总结
  4. Android分页中显示出下面翻页的导航栏的布局实例代码
  5. 详解Android中Dialog的使用
  6. android UI 设计之 Tabs
  7. 使用 标签来重用layout代码
  8. 自定义EditText
  9. [Android]simplelistadapter 与数据库绑定显示list 并且根据数据

随机推荐

  1. CPU 是怎样工作的?[每日前端夜话0x89]
  2. 造了一个 Redis 分布锁的轮子,没想到还学
  3. 链路追踪 SkyWalking 源码分析 —— Coll
  4. 作业调度中间件 Elastic-Job-Cloud 源码
  5. android framework中添加使用第三方jar包
  6. 链路追踪 SkyWalking 源码分析 —— 调试
  7. 链路追踪 SkyWalking 源码分析 —— Coll
  8. 链路追踪 SkyWalking 源码分析 —— Coll
  9. Vue生命周期钩子简介[每日前端夜话0x8A]
  10. 链路追踪 SkyWalking 源码分析 —— Agen