




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
【移動(dòng)應(yīng)用開發(fā)技術(shù)】Android如何實(shí)現(xiàn)帶動(dòng)畫柱狀圖
/upload/information/20200623/125/126985.jpg/upload/information/20200623/125/126986.gifpackage
com.lixiaodaoaaa.view.pieview;
import
android.content.Context;
import
android.graphics.Canvas;
import
android.graphics.Paint;
import
android.graphics.RectF;
import
android.support.annotation.Nullable;
import
android.util.AttributeSet;
import
android.view.View;
import
com.gcssloop.graphics.R;
import
com.lixiaodaoaaa.uitls.DensityUtils;
/**************************************
*
***
/lixiaodaoaaa
**
*
***
create
at
2017/5/18
23:45
****
*
*******
by:lixiaodaoaaa
**********
**************************************/
public
class
PColumn
extends
View
{
int
MAX
=
100;//最大
int
corner
=
40;
int
data
=
0;//顯示的數(shù)
int
tempData
=
0;
int
textPadding
=
20;
Paint
mPaint;
int
mColor;
Context
mContext;
public
PColumn(Context
context)
{
super(context);
mContext
=
context;
}
public
PColumn(Context
context,
@Nullable
AttributeSet
attrs)
{
super(context,
attrs);
mContext
=
context;
initPaint();
}
public
PColumn(Context
context,
@Nullable
AttributeSet
attrs,
int
defStyleAttr)
{
super(context,
attrs,
defStyleAttr);
mContext
=
context;
initPaint();
}
private
void
initPaint()
{
mPaint
=
new
Paint();
mPaint.setAntiAlias(true);
mColor
=
mContext.getResources().getColor(R.color.colorPrimary);
mPaint.setColor(mColor);
}
@Override
public
void
draw(Canvas
canvas)
{
super.draw(canvas);
if
(data
==
0)
{
mPaint.setTextSize(getWidth()
/
2);
RectF
oval3
=
new
RectF(0,
getHeight()
-
DensityUtils.pxTodip(mContext,
20),
getWidth(),
getHeight());//
設(shè)置個(gè)新的長方形
canvas.drawRoundRect(oval3,
DensityUtils.pxTodip(mContext,
corner),
DensityUtils.pxTodip(mContext,
corner),
mPaint);
canvas.drawText("0",
getWidth()
*
0.5f
-
mPaint.measureText("0")
*
0.5f,
getHeight()
-
DensityUtils.pxTodip(mContext,
20)
-
2
*
DensityUtils.pxTodip(mContext,
textPadding),
mPaint);
return;
}
//防止數(shù)值很大的的時(shí)候,動(dòng)畫時(shí)間過長
int
step
=
data
/
100
+
1;
if
(tempData
<
data
-
step)
{
tempData
=
tempData
+
step;
}
else
{
tempData
=
data;
}
//畫圓角矩形
String
S
=
tempData
+
"";
//一個(gè)字和兩,三個(gè)字的字號相同
if
(S.length()
<
4)
{
mPaint.setTextSize(getWidth()
/
2);
}
else
{
mPaint.setTextSize(getWidth()
/
(S.length()
-
1));
}
float
textH
=
mPaint.ascent()
+
mPaint.descent();
float
MaxH
=
getHeight()
-
textH
-
2
*
DensityUtils.pxTodip(mContext,
textPadding);
//圓角矩形的實(shí)際高度
float
realH
=
MaxH
/
MAX
*
tempData;
RectF
oval3
=
new
RectF(0,
getHeight()
-
realH,
getWidth(),
getHeight());//
設(shè)置個(gè)新的長方形
canvas.drawRoundRect(oval3,
DensityUtils.pxTodip(mContext,
corner),
DensityUtils.pxTodip(mContext,
corner),
mPaint);
//寫數(shù)字
canvas.drawText(S,
getWidth()
*
0.5f
-
mPaint.measureText(S)
*
0.5f,
getHeight()
-
realH
-
2
*
DensityUtils.pxTodip(mContext,
textPadding),
mPaint);
if
(tempData
!=
data)
{
postInvalidate();
}
}
public
void
setData(int
data,
int
MAX)
{
this.data
=
data;
tempData
=
0;
this.MAX
=
MAX;
postInvalidate();
}
}/*
*
Copyright
2016
GcsSloop
*
*
Licensed
under
the
Apache
License,
Version
2.0
(the
"License");
*
you
may
not
use
this
file
except
in
compliance
with
the
License.
*
You
may
obtain
a
copy
of
the
License
at
*
*
/licenses/LICENSE-2.0
*
*
Unless
required
by
applicable
law
or
agreed
to
in
writing,
software
*
distributed
under
the
License
is
distributed
on
an
"AS
IS"
BASIS,
*
WITHOUT
WARRANTIES
OR
CONDITIONS
OF
ANY
KIND,
either
express
or
implied.
*
See
the
License
for
the
specific
language
governing
permissions
and
*
limitations
under
the
License.
*
*
Last
modified
2016-10-02
00:22:33
*
*/
package
com.lixiaodaoaaa.graphics;
import
android.os.Bundle;
import
android.support.v7.app.AppCompatActivity;
import
com.gcssloop.graphics.R;
import
com.lixiaodaoaaa.view.pieview.PColumn;
public
class
MainActivity
extends
AppCompatActivity
{
private
PColumn
column_one;
private
PColumn
column_two;
private
PColumn
column_three;
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initAllViews();
}
private
void
initAllViews()
{
column_one
=
(PColumn)
findViewById(R.id.column_one);
column_two
=
(PColumn)
findViewById(R.id.column_two);
column_three
=
(PColumn)
findViewById(R.id.column_three);
column_one.setData(0,
100);
column_two.setData(30,
100);
column_three.setData(40,
100);
}
}<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.lixiaodaoaaa.graphics.MainActivity"
>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"/>
<com.lixiaodaoaaa.view.pieview.PColumn
android:id="@+id/column_one"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_wei
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年金屬鐠礦行業(yè)深度研究分析報(bào)告
- 2025-2030年中國荔枝果味酥行業(yè)深度研究分析報(bào)告
- 2025年人工智能軟件系統(tǒng)市場調(diào)查報(bào)告
- 2025-2030年中國包裝服務(wù)行業(yè)深度研究分析報(bào)告
- 2025-2030年中國POS收費(fèi)機(jī)項(xiàng)目投資可行性研究分析報(bào)告
- 2024-2030全球落地式拆碼盤機(jī)行業(yè)調(diào)研及趨勢分析報(bào)告
- 2024年全球及中國電子競技場館設(shè)計(jì)行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 酒類批發(fā)行業(yè)深度研究分析報(bào)告(2024-2030版)
- 2025-2030年中國乳珍奶粉行業(yè)深度研究分析報(bào)告
- 2025-2030年中國大花綠石材行業(yè)深度研究分析報(bào)告
- 2024-2025學(xué)年第二學(xué)期天域全國名校協(xié)作體高三3月聯(lián)考 地理試卷(含答案)
- 修理木橋施工合同范本
- 學(xué)校2025年每日兩小時(shí)體育活動(dòng)方案-陽光體育活力四溢
- B超的基本知識
- 錘擊式PHC預(yù)應(yīng)力混凝土管樁貫入度的控制
- 新教科版一年級科學(xué)下冊第一單元第6課《哪個(gè)流動(dòng)得快》課件
- GB/T 45107-2024表土剝離及其再利用技術(shù)要求
- 5G優(yōu)化案例:5G波束配置優(yōu)化提升CQI優(yōu)良比案例
- JT-T-1202-2018城市公共汽電車場站配置規(guī)范
- DZ∕T 0201-2020 礦產(chǎn)地質(zhì)勘查規(guī)范 鎢、錫、汞、銻(正式版)
- GB/T 18747.1-2002厭氧膠粘劑扭矩強(qiáng)度的測定(螺紋緊固件)
評論
0/150
提交評論