Layout

本文详细介绍了浏览器中的布局(layout)概念,探讨了哪些元素默认具有布局特性,以及如何通过特定的CSS属性来触发或重置布局。此外,还提供了一系列实用的CSS Hack技巧,帮助开发者解决不同版本IE浏览器中的布局问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Layout 的由来:

不同于标准属性,也不像某些浏览器的私有 CSS 属性,layout 无法通过某一个 CSS 声明直接设定 。也就是说没有”layout属性”这么一个东西,元素要么本身自动拥有 layout,要么借助一些 CSS 声明悄悄地获得 layout。

下列元素应该是默认具有 layout 的:

  • <html>, <body>
  • <table>, <tr>, <th>, <td>
  • <img>
  • <hr>
  • <input>, <button>, <select>, <textarea>, <fieldset>, <legend>
  • <iframe>, <embed>, <object>, <applet>
  • <marquee>

下列 CSS 属性和取值将会让一个元素获得 layout:

  • position: absolute
    绝对定位元素的包含区块(containing block)就会经常在这一方面出问题。
  • float: left|right
    由于 layout 元素的特性,浮动模型会有很多怪异的表现。
  • display: inline-block
    当一个内联级别的元素需要 layout 的时候往往就要用到它,这也可能也是这个 CSS 属性的唯一效果–让某个元素拥有 layout。”inline-block行为”在IE中是可以实现的,但是非常与众不同: IE/Win: inline-block and hasLayout 。
  • width: 除 “auto” 外的任意值
    当遇到layout错误的展现效果是,一般都会尝试设定高度来修复
  • height: 除 “auto” 外的任意值
    height: 1% 就在 Holly Hack 中用到。
  • zoom: 除 “normal” 外的任意值
    IE专有属性。不过 zoom: 1 可以临时用做调试。
  • writing-mode: tb-rl
    MS专有属性。
  • overflow: hidden|scroll|auto
    在 IE7 中,overflow 也变成了一个 layout 触发器,这个属性在之前版本 IE 中没有触发 layout 的功能,除非这个元素被其他情况触发添加到了一个盒子中;
  • overflow-x|-y: hidden|scroll|auto
    overflow-x 和 overflow-y 是 CSS3 盒模型中的属性,尚未得到浏览器的广泛支持。他们在之前版本IE中没有触发 layout 的功能。
  • 另外 IE7 的荧幕上又新添了几个 haslayout 的演员,如果只从 hasLayout 这个方面考虑,min/max 和 width/height 的表现类似,position 的 fixed 和 absolute 也是一模一样。
  • position: fixed
  • min-width: 任意值
    就算设为0也可以让该元素获得 layout。
  • max-width: 除 “none” 之外的任意值
  • min-height: 任意值
    即使设为0也可以让该元素的 haslayout=true
  • max-height: 除 “none” 之外的任意值

有关内联元素:

对于内联元素(可以是默认即为内联的比如 span 元素,也可以是 display: inline 的元素)

  • width 和 height 只在 IE5.x 下和 IE6 或更新版本的 quirks 模式下触发 hasLayout 。而对于 IE6,如果浏览器运行于标准兼容模式下,内联元素会忽略 width 或 height 属性,所以设置 width 或 height 不能在此种情况下令该元素具有 layout。
  • zoom 总是可以触发 hasLayout,但是在 IE5.0 中不支持。

具有”layout” 的元素如果同时也 display: inline ,那么它的行为就和标准中所说的 inline-block 很类似了:在段落中和普通文字一样在水平方向和连续排列,受 vertical-align 影响,并且大小可以根据内容自适应调整。这也可以解释为什么单单在 IE/Win 中内联元素可以包含块级元素而少出问题,因为在别的浏览器中 display: inline 就是内联,不像 IE/Win 一旦内联元素拥有 layout 还会变成 inline-block。

重置HasLayout:

如果没有其他属性再添加 hasLayout 的话,重置下列属性的默认值就会重新设置或破坏Haslayout:

  • width, height (设为 “auto”)
  • max-width, max-height (设为 “none”)(在 IE 7 中)
  • position (设为 “static”)
  • float (设为 “none”)
  • overflow (设为 “visible”) (在 IE 7 中)
  • zoom (设为 “normal”)
  • writing-mode (从 “tb-rl” 设为 “lr-t)

使用者必须小心使用这些重置属性。

display 属性的不同:当用”inline-block”设置了 haslayout = true 时,就算在一条独立的规则中覆盖这个属性为”block”或”inline”,haslayout 这个标志也不会被重置为 false。

把 mid-width, mid-height 设为它们的默认值”0″仍然会赋予 hasLayout,但是 IE 7 却可以接受一个不合法的属性”auto”来重置 hasLayout。

hasLayout脚本属性:

我们已经选择参考把“hasLayout”属性作为一个脚本属性,以便把他与我们熟悉的CSS属性区分开来;

并没有方法可以直接设置或者重置hasLayout属性;

hasLayout属性可以用来检查该元素是否有layout,例如它有一个ID=“eid”,然后可以直接在IE5.5地址栏里敲:

javascript: alert(eid.currentStyle.hasLayout)

这样就可以检测出它的状态;

IE的Developer Toolbar允许你动态的检查当前元素的样式,当hasLayout的值为“true”时,它的值被呈现为“-1”,例如,如果你想编辑一个节点的属性的时候,你可以CSS的“zoom”属性为“1”(zoom=1),这样可以触发那个hasLayout属性,以便dubug它;

另一件需要考虑的是:layout怎么作用和影响脚本(script),例如:那些没有layout特性的元素的clientWidth/clientHeight属性总是返回0,这对于新手来说是难以理解并且是莫名其妙的,并且它和Mozilla(firefox)浏览器的作用有很大出入,我们能利用这个事实来为IE5.0做决定,就像这样,如果那个clientWidth是0,那么我们说这个元素没有layout;

CSS Hacks

在IE7和它以前的版本里,下面的这些hack已经得到了验证:

John Gallant 和 Holly Bergevin在2003年发布了这个Holly hack

/* \*/
* html .gainlayout { height: 1%; }
/* */

  • 除了IE6下的标准模式里的行内元素,在IE5-6的所有版本里,这个hack都会触发所有元素的layout;
  • 除了某些极稀少的height:0或者1px,它通常工作的很好;
  • 除了在IE6的标准模式下(height:1%转化为height:auto,除非它的父元素有一个明确的高度),其他都与overflow:hidden是不相容的;
  • 在IE7的标准模式下*html不会选择任何一个元素,它是没有任何效果的;

给IE6以及它以下的版本layout,也可以用这个underscore hack:

.gainlayout { _height: 0; }

并且为了给IE7layout,我们可以用min-hight属性:

.gainlayout { min-height: 0; }

二者选一的,这是比较有效的功能,就是conditional comments:

<!–[if lte IE 6]>
<style>
.gainlayout { height: 1px; }
</style>
<![endif]–>

在外部样式表引入之时,插入一条受限制的注释,是比较简洁和可靠的解决办法:

<link rel=”stylesheet” href=”allbrowsers.css” type=”text/css” />

<!–[if lte IE 7]>
<link rel=”stylesheet” href=”iefix.css” type=”text/css” />
<![endif]–>

给IE6及他以下的版本设定高度总是被用到的,除非他和某些特性冲突(overflow:hidden);那些1%,1px或者0基本上都是相等的,但是那个1%有时候会出现一些问题(即使极少碰到);

在标准模式下给元素设定高度是不可用的,在IE7里应该尽可能避免(或者小心的使用:两个条件:<1>只能是百分值<2>其父元素必须没有确定的高度),鉴于这些原因,我们喜欢用:dispaly:inline-block或者zoom:1;

我们已经对那些浮动(float)元素试验了“holy”hacks,或者那些已经拥有宽度(width)的元素,记住这个目标就是:不能运用这些hacks在拥有height的元素上,因为这样会触发hasLayout=ture;

不要对所有的元素这样:

* {_height: 1px;}

这样是不合适的,因为它不仅仅让拥有layout的没有变好,反而改变了那些基本元素的渲染和展示;

hack管理(management):

尽管IE7已经发布了,但是我们仍然不能预见将来的IE版本是否继续需要hasLayout来修复bug和他们是怎么相互作用的,所以用MS的私有属性zoom或者有田间的条件注释是明智的:

<!–[if lt IE 7]><style>
/* style for IE6 + IE5.5 + IE5.0 */
.gainlayout { height: 0; }
</style><![endif]–>

<!–[if IE 7]><style>
.gainlayout { zoom: 1; }
</style><![endif]–>

  • zoom:1,它给IE5.5以上的所有版本里的任何元素layout(包括行内元素),但是这个规则在IE5.0里没有效果;
  • 未知的副作用(尽管行内元素表现的像行内块元素);
  • 如果一定要确定,zoom一定要被有条件的注释隐藏;

如果想得到一个更详尽的hasLayout触发和hasLayout在不同的IE版本里的比较的话,请参考这里:Thoughts on IE hack management.

IE Mac简短介绍:

IE Mac和IE for Windows是十分不同的,每一种都有自己的渲染引擎,IE Mac用任何方式都不知道hasLayout的行为,IE Mac渲染引擎是在向标准遵循模式靠近。

要求参考已有的activity_add_task.xml内容如下,并给出完整的activity_edit_task.xml:<?xml version="1.0" encoding="utf-8"?> <androidx.core.widget.NestedScrollView xmlns: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" android:background="@color/light_background" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <!-- 标题栏 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingBottom="16dp" android:text="创建新任务" android:textColor="@color/primary_dark" android:textSize="24sp" android:textStyle="bold" /> <!-- 必填项卡片 --> <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:cardCornerRadius="12dp" app:cardElevation="4dp" app:strokeColor="@color/primary_light" app:strokeWidth="1dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <!-- 卡片标题 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableStart="@drawable/ic_info_outline" android:drawablePadding="8dp" android:gravity="center_vertical" android:paddingBottom="12dp" android:text="必填信息" android:textColor="@color/primary_dark" android:textSize="18sp" android:textStyle="bold" /> <!-- 任务标题 --> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="任务标题 *" app:boxStrokeColor="@color/primary" app:errorEnabled="true"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/taskTitleEditText" style="@style/CustomTextInputEditText" android:layout_width="match_parent" android:layout_height="wrap_content" /> </com.google.android.material.textfield.TextInputLayout> <!-- 分类选择 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="分类 *" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <!-- 分类按钮组 - 紧凑布局 --> <com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/categoryToggleGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:selectionRequired="true" app:singleSelection="true"> </com.google.android.material.button.MaterialButtonToggleGroup> <!-- 重要性行 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="重要性 *" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:gravity="center_vertical" android:orientation="horizontal" android:paddingVertical="10dp"> <RatingBar android:id="@+id/importanceRatingBar" style="@style/Widget.AppCompat.RatingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:isIndicator="false" android:numStars="5" android:progressBackgroundTint="@color/light_gray" android:progressTint="@color/primary" android:rating="3" android:stepSize="1" android:theme="@style/RatingBarStyle" /> <TextView android:id="@+id/ratingText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="中等" android:textColor="@color/primary_dark" android:textSize="16sp" /> </LinearLayout> <!-- 期待完成时长 - 标签和设置在同一行 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:gravity="center_vertical" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:text="期待完成时长 *" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <TextView android:id="@+id/durationDisplay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0 分钟" android:textColor="@color/red" android:textSize="14sp" /> </LinearLayout> <!-- 时间增加按钮行 - 完全按照原界面设计 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:orientation="horizontal"> <TextView android:id="@+id/add60TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+60" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/add30TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+30" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/add15TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+15" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/add10TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+10" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/add5TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+5" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/add1TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="+1" android:textColor="@color/primary_dark" android:textSize="14sp" /> </LinearLayout> <!-- 时间减少按钮行 - 完全按照原界面设计 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/reduce60TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-60" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/reduce30TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-30" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/reduce15TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-15" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/reduce10TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-10" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/reduce5TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-5" android:textColor="@color/primary_dark" android:textSize="14sp" /> <TextView android:id="@+id/reduce1TextView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="?selectableItemBackground" android:clickable="true" android:focusable="true" android:gravity="center" android:padding="8dp" android:text="-1" android:textColor="@color/primary_dark" android:textSize="14sp" /> </LinearLayout> </LinearLayout> </com.google.android.material.card.MaterialCardView> <!-- 子任务卡片 - 新增独立卡片 --> <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:cardCornerRadius="12dp" app:cardElevation="4dp" app:strokeColor="@color/primary_light" app:strokeWidth="1dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <!-- 子任务标题 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableStart="@drawable/ic_subtask" android:drawablePadding="8dp" android:gravity="center_vertical" android:paddingBottom="12dp" android:text="子任务" android:textColor="@color/primary_dark" android:textSize="18sp" android:textStyle="bold" /> <!-- 添加子任务按钮 --> <com.google.android.material.button.MaterialButton android:id="@+id/addSubtaskButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:drawableStart="@drawable/ic_add_24dp" android:drawableTint="@color/primary" android:text="添加子任务" android:textColor="@color/primary" app:iconGravity="textStart" /> <!-- 子任务列表 --> <LinearLayout android:id="@+id/subtasksContainer" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="2dp"> <!-- 空状态提示 --> <TextView android:id="@+id/emptySubtasksText" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="24dp" android:text="暂无子任务,点击上方按钮添加" android:textColor="#888" /> </LinearLayout> </LinearLayout> </com.google.android.material.card.MaterialCardView> <!-- 可选项折叠面板 --> <com.google.android.material.card.MaterialCardView android:id="@+id/expandableCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:cardCornerRadius="12dp" app:cardElevation="2dp"> <!-- 折叠面板标题 --> <LinearLayout android:id="@+id/expandableHeader" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/selectableItemBackground" android:minHeight="56dp" android:orientation="horizontal" android:padding="16dp"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableStart="@drawable/ic_baseline_tune_24" android:drawablePadding="8dp" android:gravity="center_vertical" android:text="更多选项" android:textColor="@color/primary" android:textSize="16sp" android:textStyle="bold" /> <ImageView android:id="@+id/expandIcon" android:layout_width="24dp" android:layout_height="24dp" android:layout_gravity="center" android:src="@drawable/ic_baseline_expand_more_24" app:tint="@color/primary" /> </LinearLayout> <!-- 可选项内容(默认折叠) --> <LinearLayout android:id="@+id/expandableContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:orientation="vertical" android:padding="16dp" android:visibility="gone"> <!-- 任务执行日期 - 移动到更多选项中 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="任务执行日期" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <!-- 日期选项组 - 减少间距确保文本完整显示 --> <com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/dateToggleGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:selectionRequired="true" app:singleSelection="true"> <com.google.android.material.button.MaterialButton android:id="@+id/btnToday" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="今天" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnTomorrow" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="明天" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnSelectDate" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="选择日期" app:backgroundTint="@color/button_background_selector" /> <!-- 确保"没有日期"完全显示 --> <com.google.android.material.button.MaterialButton android:id="@+id/btnNoDate" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1.2" android:text="没有日期" app:backgroundTint="@color/button_background_selector" /> </com.google.android.material.button.MaterialButtonToggleGroup> <!-- 父级目标 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="父级目标" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="选择父级目标" app:boxStrokeColor="@color/primary_light" app:hintTextColor="@color/gray_500" app:startIconTint="@color/primary"> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/parentTargetAutoComplete" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="none" android:padding="3dp" android:paddingLeft="8dp" /> </com.google.android.material.textfield.TextInputLayout> <!-- 重复选项 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="重复选项" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <!-- 重复选项组 - 增加"每年"选项并调整间距 --> <com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/repeatToggleGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:selectionRequired="true" app:singleSelection="true"> <com.google.android.material.button.MaterialButton android:id="@+id/btnNoRepeat" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="不重复" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnDaily" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="每日" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnWeekly" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="每周" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnMonthly" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="2dp" android:layout_weight="1" android:text="每月" app:backgroundTint="@color/button_background_selector" /> <!-- 新增每年选项 --> <com.google.android.material.button.MaterialButton android:id="@+id/btnYearly" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="每年" app:backgroundTint="@color/button_background_selector" /> </com.google.android.material.button.MaterialButtonToggleGroup> <!-- 任务描述 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="任务描述" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="详细描述任务内容..." app:boxStrokeColor="@color/primary_light" app:startIconDrawable="@drawable/ic_baseline_description_24" app:startIconTint="@color/primary"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/taskDescriptionEditText" style="@style/CustomTextInputEditText" android:layout_width="match_parent" android:layout_height="120dp" android:gravity="top" android:inputType="textMultiLine" /> </com.google.android.material.textfield.TextInputLayout> <!-- 提醒设置 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="提醒设置" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:orientation="vertical"> <androidx.appcompat.widget.SwitchCompat android:id="@+id/reminderSwitch" android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="false" android:text="启用提醒" android:textColor="@color/gray_500" /> <LinearLayout android:id="@+id/reminderOptionsLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:orientation="horizontal" android:visibility="gone"> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_weight="1" android:hint="提前时间" app:boxStrokeColor="@color/primary_light"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/reminderTimeEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" /> </com.google.android.material.textfield.TextInputLayout> <Spinner android:id="@+id/reminderUnitSpinner" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> </LinearLayout> <!-- 任务状态 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="任务状态" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/statusToggleGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:selectionRequired="true" app:singleSelection="true"> <com.google.android.material.button.MaterialButton android:id="@+id/btnNotStarted" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="未开始" app:backgroundTint="@color/button_background_selector" /> <com.google.android.material.button.MaterialButton android:id="@+id/btnInProgress" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="进行中" app:backgroundTint="@color/button_background_selector" /> </com.google.android.material.button.MaterialButtonToggleGroup> <!-- 进度设置 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="进度 (%)" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:gravity="center_vertical" android:orientation="horizontal"> <SeekBar android:id="@+id/progressSeekBar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:max="100" android:progress="0" /> <TextView android:id="@+id/progressText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="0%" android:textColor="@color/primary_dark" android:textSize="16sp" /> </LinearLayout> <!-- 创建时机选择 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="创建时机" android:textColor="@color/primary_dark" android:textSize="14sp" android:textStyle="bold" /> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" app:boxStrokeColor="@color/primary" app:startIconDrawable="@drawable/ic_baseline_access_time_24" app:startIconTint="@color/primary"> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/creationTimingSpinner" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="false" android:hint="选择创建时机" android:inputType="none" /> </com.google.android.material.textfield.TextInputLayout> </LinearLayout> </com.google.android.material.card.MaterialCardView> <!-- 操作按钮 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" android:paddingTop="8dp"> <com.google.android.material.button.MaterialButton android:id="@+id/cancelButton" style="@style/CompactButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_weight="1" android:text="取消" android:textColor="@color/primary_dark" app:backgroundTint="@color/light_gray" /> <com.google.android.material.button.MaterialButton android:id="@+id/createButton" style="@style/Widget.MaterialComponents.Button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_weight="1" android:text="创建任务" android:textColor="@color/white" app:backgroundTint="@color/primary" /> </LinearLayout> </LinearLayout> </androidx.core.widget.NestedScrollView>
最新发布
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值