日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android自定义Layout

發布時間:2025/6/15 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android自定义Layout 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在開發Android過程中,有時已有的Loyout布局不能完全滿足設計需求,這時需要在已有的Layout基礎上上進行擴展,以達到通過配置文件描述布局的設計原則。

首先第一一個布局類,重寫其onDraw方法。

Java代碼??
  • public?static?class?iRelativeLayout?extends?RelativeLayout??
  • ????{??
  • ????????private?Paint???mPaint;??
  • ????????private?Rect????mRect;??
  • ??
  • ????????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);??
  • ????????}??
  • ??
  • ????????@Override??
  • ????????protected?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"?>

    ?

    <view xmlns:android="http://schemas.android.com/apk/res/android"

    class="iRelativeLayout"

    ?? ?android:orientation="vertical"

    ?? ?android:layout_width="fill_parent"

    ?? ?android:layout_height="fill_parent"

    ?? ?android:background = "#C5CCD4FF"

    >

    <LinearLayout

    android:id = "@+id/TabLayout_One"

    android:layout_width = "fill_parent"

    android:layout_height = "fill_parent"

    android:layout_above = "@+id/Tabs"

    >

    <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">

    <RelativeLayout

    android:layout_width = "fill_parent"

    android:layout_height = "fill_parent"

    android:visibility = "visible"

    >

    <Button

    android:id = "@+id/ButtonOne"

    android:layout_width = "wrap_content"

    android:layout_height = "fill_parent"

    android:text = "h3h3h3"

    />

    <Button

    android:id = "@+id/ButtonTwo"

    android:layout_width = "wrap_content"

    android:layout_height = "wrap_content"

    android:text = "11222"

    android:layout_below ="@+id/ButtonOne"

    />

    <Button

    android:id = "@+id/ButtonThree"

    android:layout_width = "wrap_content"

    android:layout_height = "wrap_content"

    android:text = "wass"

    android:layout_below ="@+id/ButtonTwo"

    />

    </RelativeLayout>

    </ScrollView>

    </LinearLayout>

    </view>

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

    總結

    以上是生活随笔為你收集整理的Android自定义Layout的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。