欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義時(shí)間軸的實(shí)現(xiàn)過(guò)程

 更新時(shí)間:2017年01月25日 10:33:19   作者:zhiyuan0932  
這篇文章主要介紹了Android自定義時(shí)間軸的實(shí)現(xiàn)過(guò)程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文講述Android自定義時(shí)間軸的實(shí)現(xiàn)過(guò)程,供大家參考,具體內(nèi)容如下

相關(guān)視頻鏈接:
Android自定義控件系列
http://edu.csdn.net/course/detail/3719/65396
Android視頻全系列
http://edu.csdn.net/course/detail/2741/43163

時(shí)間軸效果,實(shí)際上非常簡(jiǎn)單,就是listView中一個(gè)又一個(gè)的條目而已….大家可以只關(guān)注一個(gè)條目。
首先展示一個(gè)條目的布局效果

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="75dp"
 android:orientation="horizontal" >

 <!-- 線條部分 -->

 <LinearLayout
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:gravity="center_horizontal"
 android:orientation="vertical"
 android:paddingLeft="30dp" >

 <View
 android:layout_width="3dp"
 android:layout_height="20dp"
 android:background="#88000000" />

 <com.example.time.TimeView
 android:src="@drawable/ic_launcher"
 android:id="@+id/timeView"
 android:layout_width="40dp"
 android:layout_height="40dp" />
 <View
 android:layout_width="3dp"
 android:layout_height="40dp"
 android:background="#88000000" />
 </LinearLayout>
 <!-- 文字部分 -->

 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:paddingLeft="30dp"
 android:paddingRight="30dp"
 android:paddingTop="20dp" >

 <TextView
 android:id="@+id/tv_content"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="哈哈哈"
 android:textColor="#ABABAB" />

 <TextView
 android:id="@+id/tv_time"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/tv_content"
 android:text="時(shí)間"
 android:textColor="#ABABAB" />
 </LinearLayout>

</LinearLayout>

接下來(lái)看一下自定義的TimeView如何書(shū)寫(xiě)

package com.example.time;

import java.util.Random;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

public class TimeView extends View {

 private Random random;
 private String time;
 private Rect mBounds = new Rect();
 private int rgb;
 public TimeView(Context context, AttributeSet attrs, int defStyleAttr) {
 super(context, attrs, defStyleAttr);
 initView();
 }

 public TimeView(Context context, AttributeSet attrs) {
 super(context, attrs);
 initView();
 }

 public TimeView(Context context) {
 super(context);
 initView();
 }

 private void initView() {

 random = new Random();
 //定義顏色---這里純粹為了好玩--大家定義的時(shí)候可以在自定義控件外邊定義,將顏色傳遞進(jìn)來(lái)
 rgb = Color.rgb(100+random.nextInt(155), 100+random.nextInt(155),
 random.nextInt(100+155));

 }

 public void setTime(String time) {
 this.time = time;
 invalidate();

 }

 @Override
 protected void onDraw(Canvas canvas) {
 super.onDraw(canvas);
 Paint paint = new Paint();
 paint.setColor(rgb);
 paint.setAntiAlias(true);
 paint.setStyle(Style.FILL_AND_STROKE);
 //先繪制圓
 canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2,
 paint);
 paint = new Paint();
 paint.setColor(Color.BLACK);
 paint.setTextSize(30);
 paint.getTextBounds(time, 0, time.length(), mBounds);
 float textWidth = mBounds.width();
 float textHeight = mBounds.height();
 //再繪制文字
 canvas.drawText(time, getWidth() / 2 - textWidth / 2, getHeight() / 2
 + textHeight / 2, paint);
 }

}

看一下Activity中的代碼–就是一個(gè)ListView的效果展示

public class MainActivity extends Activity {

 private ListView listView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 listView = (ListView) findViewById(R.id.listView);
 initData();
 listView.setAdapter(new MyBaseAdapter());
 }

 class MyBaseAdapter extends BaseAdapter {

 @Override
 public int getCount() {
 return dataList.size();
 }

 @Override
 public Object getItem(int arg0) {
 return dataList.get(arg0);
 }

 @Override
 public long getItemId(int arg0) {
 return arg0;
 }

 @Override
 public View getView(int arg0, View arg1, ViewGroup arg2) {

 View view = View.inflate(MainActivity.this, R.layout.item, null);
 TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
 TextView tv_time = (TextView) view.findViewById(R.id.tv_time);
 TimeView timeView = (TimeView) view.findViewById(R.id.timeView);
 timeView.setTime(dataList.get(arg0).getTime());
 tv_content.setText(dataList.get(arg0).getContent());
 tv_time.setText(dataList.get(arg0).getTime());

 return view;
 }

 }

 ArrayList<DataBean> dataList = new ArrayList<DataBean>();

 private void initData() {
 for (int i = 0; i < 20; i++) {
 dataList.add(new DataBean("哈哈哈哈" + i, "25/10"));
 }

 }

}

好了,這樣的一個(gè)自定義時(shí)間軸效果就搞定了。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android通過(guò)AIDL在兩個(gè)APP之間Service通信

    Android通過(guò)AIDL在兩個(gè)APP之間Service通信

    這篇文章主要為大家詳細(xì)介紹了Android通過(guò)AIDL在兩個(gè)APP之間Service通信,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android編寫(xiě)2048小游戲

    Android編寫(xiě)2048小游戲

    這篇文章主要為大家詳細(xì)介紹了利用Android編寫(xiě)一個(gè)2048小游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android用webView包裝WebAPP方法

    Android用webView包裝WebAPP方法

    本篇文章通過(guò)流程講解給大家詳細(xì)介紹了Android用webView包裝WebAPP的方法以及需要注意的地方,需要的朋友參考學(xué)習(xí)下。
    2018-02-02
  • Android利用Sensor(傳感器)實(shí)現(xiàn)水平儀功能

    Android利用Sensor(傳感器)實(shí)現(xiàn)水平儀功能

    這篇文章主要為大家詳細(xì)介紹了Android利用Sensor傳感器實(shí)現(xiàn)水平儀功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android繪圖技巧使用詳解

    Android繪圖技巧使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android繪圖技巧的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android小米推送簡(jiǎn)單使用方法

    Android小米推送簡(jiǎn)單使用方法

    這篇文章主要為大家詳細(xì)介紹了Android小米推送簡(jiǎn)單使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android文字匹配度算法及實(shí)際應(yīng)用示例

    Android文字匹配度算法及實(shí)際應(yīng)用示例

    本文介紹了Android應(yīng)用中常用的文字匹配度算法Levenshtein Distance,并給出了實(shí)際應(yīng)用示例,通過(guò)合理選擇和應(yīng)用文字匹配度算法,可以實(shí)現(xiàn)多種功能,提升用戶體驗(yàn),增強(qiáng)應(yīng)用的實(shí)用性,需要的朋友可以參考下
    2024-05-05
  • Android Studio實(shí)現(xiàn)格式化XML代碼順序

    Android Studio實(shí)現(xiàn)格式化XML代碼順序

    這篇文章主要介紹了Android Studio實(shí)現(xiàn)格式化XML代碼順序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Android視頻加水印之FFmpeg的簡(jiǎn)單應(yīng)用實(shí)例

    Android視頻加水印之FFmpeg的簡(jiǎn)單應(yīng)用實(shí)例

    最近有個(gè)需求,需要錄制視頻,能添加水印,所以下面這篇文章主要給大家介紹了關(guān)于Android視頻加水印之FFmpeg的簡(jiǎn)單應(yīng)用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-05-05
  • Android中button點(diǎn)擊后字體的變色效果

    Android中button點(diǎn)擊后字體的變色效果

    button的點(diǎn)擊效果無(wú)疑是非常簡(jiǎn)單的,接下來(lái)通過(guò)本文給大家介紹下如何添加button點(diǎn)擊的字體顏色變化效果,感興趣的朋友一起看看吧
    2016-10-10

最新評(píng)論