自定義View遇到的相關問題

2021-07-08 10:29:01 字數 1443 閱讀 4106

1、在scrollview中加入自定義view

(1),首先是要做乙個水平滾動條,發現用scrollview 設定屬性android:scrollbars ="horizontal"居然不行,然後才發 現要用horizontalscrollview,真是醉了

(2),需要horizontalscrollview不顯示滾動條,解決如下:

android:scrollbars="none"
(3),view的實際寬度為0,原因是沒有重寫onmeasure,當父容器可以無限大時子容器卻會size=0

解決如下

int screenwidth;

int screenheight;

screenwidth=manager.getdefaultdisplay().getwidth();

screenheight=manager.getdefaultdisplay().getheight();

@override

public void onmeasure(int widthmeasurespec,int heightmeasurespec)

(4),paint畫圓弧的時候發現圓弧角度小於360時不會顯示,這裡其實錯的地方很明顯,當我們把矩形的top和bottom弄反時就會出現這樣的問題

//rectf oval=new rectf(50,500,150,400);//--------------------->錯誤

rectf oval=new rectf(50,400,150,500);//--------------------->正確

canvas.drawarc(oval, 90, 270, false, p);

(5), paint設定透明度無效果:

paint設定透明度必須要在設定顏色之後,否則無效果

paint piebglinep=new paint();

piebglinep.setstrokewidth(5);

piebglinep.setcolor(getresources().getcolor(r.color.chart_pie_bg_line));

piebglinep.setalpha(145);//有效果

paint piebglinep=new paint();

piebglinep.setstrokewidth(5);

piebglinep.setalpha(145);//無效果

piebglinep.setcolor(getresources().getcolor(r.color.chart_pie_bg_line));

Android自定義View相關總結

通常用於實現複雜的 不規則的效果,需要自己支援wrap content和padding。自定義圓形進度條元件的kotlin class mycircleprogress view constructor context context,attr attributeset super context,...

安卓自定義繪製View中遇到的問題

第乙個建構函式 public mycustomview context context 第二個建構函式 public mycustomview context context,attributeset attrs 第三個建構函式 public mycustomview context context...

畢設遇到的問題(三) 自定義view

畢設已經處於收工階段了,現在的主要任務就是優化一下資料統計功能了。為了直觀的表示我的課程表應用中的簽到記錄功能,最好的方式莫過於座標圖,橫軸表示周,縱軸表示簽到次數。這樣若是學霸型別的童鞋,他們的簽到記錄表示在座標圖中定是一條水平的柱狀圖,而學弱呢,可能就是起起伏伏了。如下圖,直接拿的測試簽到資料做...