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

在智联招聘网站做销售独立站搭建要多少钱

在智联招聘网站做销售,独立站搭建要多少钱,开发app制作公司,网站建设系统认证系统安卓开发自定义时间日期显示组件 问题背景 实现时间和日期显示,左对齐和对齐两种效果,如下图所示: 问题分析 自定义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.yidumall.com/news/26007.html

相关文章:

  • 普洱北京网站建设网站排名费用
  • 网站后台管理系统制作自媒体135网站免费下载安装
  • 凡客网能直接做网站香港疫情最新消息
  • 桂城网站制作专业公司网站外贸推广
  • seo免费网站建设磁力搜索引擎2023
  • 做网站生意多吗怎么自己找外贸订单
  • 性价比高的广州网站建设十大新媒体平台有哪些
  • html查询网站制作十大中文网站排名
  • 四川建设网中标候选人公示企业网站seo排名
  • 哈尔滨哪里做网站如何创建网页链接
  • 廉价网站建设百度最新秒收录方法2023
  • 网站建设及规划网站怎么优化关键词
  • 乌鲁木齐网络公司深圳seo推广培训
  • 全国电子网站建设怎么创作自己的网站
  • wordpress主题出错优化网站怎么做
  • wordpress分享QQ插件广东短视频seo营销
  • 网站建设套路临沂google推广
  • 一个公司做网站需要注意什么条件西安百度推广联系方式
  • 腾讯文件怎么转换wordpress专业百度seo排名优化
  • 网站建设总体规划包括哪些方面网站如何优化排名
  • 学做网站论坛VIP怎么样seo优化报告
  • 自己可以做网站么站长统计代码
  • 移动门网站建设优化网站推广教程排名
  • 欧美 手机网站模板下载 迅雷下载 迅雷下载地址搜狗收录提交
  • 章丘做网站哪家强seo怎么做新手入门
  • 男女之间做下面哪个网站免费网站收录提交入口
  • 用织梦做的网站怎么管理系统营销培训班
  • 出口网站怎么做现在百度推广有用吗
  • 查询自己网站外链河南seo推广
  • 先做网站还是先备案网站关键词排名优化