当前位置: 首页 > news >正文

济南网站建设 伍际网络广西桂林阳朔有哪些旅游景点

济南网站建设 伍际网络,广西桂林阳朔有哪些旅游景点,邵阳属于哪个省哪个市,酷奇趣wordpress邀请码安卓开发自定义时间日期显示组件 问题背景 实现时间和日期显示,左对齐和对齐两种效果,如下图所示: 问题分析 自定义view实现一般思路: (1)自定义一个View (2)编写values/attrs.…

安卓开发自定义时间日期显示组件

问题背景

实现时间和日期显示,左对齐和对齐两种效果,如下图所示:
在这里插入图片描述

问题分析

自定义view实现一般思路:
(1)自定义一个View
(2)编写values/attrs.xml,在其中编写styleable和item等标签元素
(3)在布局文件中View使用自定义的属性
(4)在View的构造方法中通过TypedArray获取

问题解决

话不多说,直接上代码
(1)编写values/attrs.xml,组件定义left属性

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="TimeClockView"><attr name="left" format="boolean"/></declare-styleable>
</resources>

(2)自定义View,代码如下:

public class TimeClockView extends LinearLayout {boolean isLeft = true;public TimeClockView(Context context) {super(context);initView(context);}private void initView(Context context) {if (isLeft) {LayoutInflater.from(context).inflate(R.layout.layout_time_date,this);} else {LayoutInflater.from(context).inflate(R.layout.layout_time_date1,this);}}public TimeClockView(Context context, AttributeSet attrs) {super(context, attrs);initTypeValue(context,attrs);initView(context);}public void initTypeValue(Context context ,AttributeSet attrs){TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TimeClockView);isLeft = a.getBoolean(R.styleable.TimeClockView_left, true);a.recycle();}
}

(3)自定义view对应的布局文件如下:
左对齐:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextClockandroid:id="@+id/time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:format12Hour="hh:mm"android:format24Hour="HH:mm"android:textSize="40px" /><TextClockandroid:id="@+id/date"android:layout_below="@id/time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:format12Hour="MM月dd日 E"android:format24Hour="MM月dd日 E"android:textSize="20px" />
</LinearLayout>

右对齐:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:gravity="end"android:orientation="vertical"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextClockandroid:id="@+id/time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:format12Hour="hh:mm"android:format24Hour="HH:mm"android:textSize="40px" /><TextClockandroid:id="@+id/date"android:layout_below="@id/time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:format12Hour="MM月dd日 E"android:format24Hour="MM月dd日 E"android:textSize="20px" />
</LinearLayout>

(4)在页面布局中,使用自定义的view

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><com.baorant.mytestnew.view.TimeClockViewandroid:layout_marginLeft="90px"android:layout_marginTop="70px"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent"android:layout_width="wrap_content"android:layout_height="wrap_content" /><com.baorant.mytestnew.view.TimeClockViewandroid:layout_marginRight="90px"android:layout_marginTop="70px"app:left="false"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"android:layout_width="wrap_content"android:layout_height="wrap_content"/></androidx.constraintlayout.widget.ConstraintLayout>
http://www.yayakq.cn/news/731461/

相关文章:

  • 网站首页布局设计原理怎么用电脑给域名做网站
  • 选择郑州网站建设广州前20跨境电商公司
  • 在线制作图片网站有哪些明年做那些网站能致富
  • 创建免费网站需要什么条件外贸网站建设商家
  • 天津网站建设 易尔通秦皇岛网站制作源码
  • 中国外贸网站排名专门做本子的网站
  • 卡盟建设vip网站如何开发cms网站
  • 有网站用nodejs做后台手机端网站开发源码
  • 做网站购买什么dw做网站图片运用
  • 旅游网站规划设计与建设wordpress the7 官网
  • 自己的网站怎么接广告哪块行业需要网站建设
  • 国外的做的比较优秀的网站有哪些成都网站设计合理柚v米科技
  • 青海住房和城乡建设厅网站株洲定制型网站建设
  • 深圳网站建设认准乐云游戏门户网站建设
  • 织梦做网站被告高水平大学建设大学网站
  • 网站如何做问卷调查问卷郑州网站优化公司价位
  • 黑龙江省网站建设网站中添加百度地图
  • 静态网站什么意思品牌高端网站制作官网
  • 安徽网站建设制作做网站需要哪些栏目
  • 外贸专业网站网络直播平台
  • 购物优惠券网站怎么做郴州市简介
  • 网站制作的关键技术广丰网站建设
  • 网站做实名验证码无锡外贸网站开发
  • 高端网站设计开发免费网页下载
  • 学校如何建网站网页设计购物网站模板
  • 0基础学网站开发怎么看网站室哪做的
  • 最新网站信息方案设计评分标准
  • 湖北专业网站建设口碑好wordpress 判断版本号
  • 查询网站到期时间手机app开发成本
  • html5的网站有哪些上海广告公司电话