- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何在不使用任何库的情况下实现这种布局?
我尝试过类似的方法,但无法获得准确的布局
my_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_marginTop="20dp"
tools:context=".MainActivity">
<RelativeLayout
android:background="@drawable/layout_border"
android:layout_margin="20dp"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_tick"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_marginLeft="20dp"
android:src="@drawable/tick" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/iv_tick"
android:layout_marginLeft="14dp"
android:layout_marginRight="20dp"
android:layout_toRightOf="@+id/iv_tick"
android:lineSpacingExtra="6dp"
android:text="This is my text. This is my text. This is my text. This is my text. "
android:textColor="#000"
android:textSize="16dp" />
<ImageView
android:src="@drawable/dotted_line"
android:foregroundGravity="left"
android:layout_below="@+id/iv_tick"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<!--<com.example.myapplication.DividerView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layerType="software"
android:color="#ff0000"
android:orientation="vertical"
android:dashLength="5dp"
android:dashGap="1dp"
android:dashThickness="1dp" />-->
</RelativeLayout>
</RelativeLayout>
dotted_line.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="4dp"
android:dashGap="4dp" />
</shape>
</rotate>
这是我用上面实现的代码得到的结果。如何获得类似于我上面发布的图片的结果?
我什至尝试过约束布局,但也没有帮助。
最佳答案
输出:
使用这个:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_5"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginStart="@dimen/spacing_smlarge"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="@color/grey_10" />
<ImageView
android:layout_width="@dimen/spacing_middle"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_large"
android:tint="#9CCC65"
app:srcCompat="@drawable/shape_round_solid" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:visibility="visible"
app:cardCornerRadius="2dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Taylor W "
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginStart="@dimen/spacing_smlarge"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="@color/grey_10" />
<ImageView
android:layout_width="@dimen/spacing_middle"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_large"
android:tint="#29B6F6"
app:srcCompat="@drawable/shape_round_solid" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:visibility="visible"
app:cardCornerRadius="2dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Taylor W "
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginStart="@dimen/spacing_smlarge"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="@color/grey_10" />
<ImageView
android:layout_width="@dimen/spacing_middle"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_large"
android:tint="#FF4081"
app:srcCompat="@drawable/shape_round_solid" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:visibility="visible"
app:cardCornerRadius="2dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Taylor W "
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginStart="@dimen/spacing_smlarge"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="@color/grey_10" />
<ImageView
android:layout_width="@dimen/spacing_middle"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_large"
android:tint="#F57F17"
app:srcCompat="@drawable/shape_round_solid" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:visibility="visible"
app:cardCornerRadius="2dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Taylor W "
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
在drawable文件夹名drawable/shape_round_solid
中创建一个drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorAccent" />
<size
android:width="15dp"
android:height="15dp" />
</shape>
添加这个 dimens.xml
<!--genaral spacing-->
<dimen name="spacing_xsmall">2dp</dimen>
<dimen name="spacing_small">3dp</dimen>
<dimen name="spacing_medium">5dp</dimen>
<dimen name="spacing_xmedium">7dp</dimen>
<dimen name="spacing_middle">10dp</dimen>
<dimen name="spacing_large">15dp</dimen>
<dimen name="spacing_smlarge">18dp</dimen>
<dimen name="spacing_mlarge">20dp</dimen>
<dimen name="spacing_mxlarge">25dp</dimen>
<dimen name="spacing_xlarge">35dp</dimen>
<dimen name="spacing_xmlarge">40dp</dimen>
<dimen name="spacing_xxlarge">50dp</dimen>
<dimen name="spacing_xxxlarge">55dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
希望这对所有人都有效。
关于android - 如何在Android中实现图像下方的垂直虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55135893/
我正在使用matplotlib创建简单的线图。我的图是一个简单的时间序列数据集,其中我沿x轴有时间,而我在y轴上有测量的值。 y值可以具有正值或负值,如果y值> 0,则我想用蓝色填充行上方和下方的颜色
我有一个简单的菜单,当单击菜单项时,该菜单会滚动到某个部分。 例如: Contact 将滚动到: 但是我也有一个始终粘在顶部的菜单,并且该菜单的高度不是用滚动脚本计算的。因此菜单总是悬停在元素的顶部
我有一个 UISearchBar 和 UISearchDisplayController,一切都很好,但我的范围选择器显示在文本字段旁边而不是下方。我知道这是设备横向时的预期操作,但由于我在 UISp
因此,我正在创建一个根据用户输入增大和缩小的 ListView ,我需要四个按钮,但我不知道如何让按钮与 ListView 的底部对齐并位于2x2 网格时尚。我已经尝试过相对布局,但似乎不起作用。谢谢
我正在使用的系统无法直接编辑每个页面上的 HTML。我想添加特定页面正文的顶部,但我输入 HTML 的框会自动将脚本放置在上面 我尝试过这个: $('body').prepend(''); 任何帮
设计模式一切都很好,但在实时导航栏位于 ScrollView 下方我该如何解决这个问题?请帮忙 最佳答案 同样,在没有看到任何代码的情况下很难说,但我相信导航栏根本没有显示。如果您直接从另一个 Vie
我现在必须重用和修改其他人的代码来创建图像处理应用程序。以下代码用于设置框架及其 GUI。我遇到的问题是,当在菜单栏上单击文件字时,菜单项列在 originalImage 容器中包含的 Canvas
我创建了一个 Angular 指令,用户可以在其中根据一天中的时间更改某些设置。下面是我已有的图片: 我想在 div 的 x 轴上添加一种准确表示时间的“滴答”,以向用户显示他在做什么,如下图所示:
这是下面的代码。 body { font-family: "Lato", sans-serif; } .sidenav { width: 130px; positio
这个问题在这里已经有了答案: Z-Index not working? [closed] (1 个回答) 关闭 5 年前。
我搜索了这个并尝试了 Z 轴的东西,但无济于事。基本上,我的导航栏在其下方的 div 下方显示有子菜单。那个 div 发生了不透明的事情,这一定与它有关。我需要这些显示在 div 上方!! JS fi
我正在处理的网站的某些页面使用脚本自动创建基于页面标题的目录。但是,我在获取“toc”div 以将页面的其余内容推送到其下方时遇到了一些问题。 TOC div 在我页面的最里面的 div 中,“con
我的代码 http://jsfiddle.net/p796z/1/ HTML Content Content Content Content Content Content
请看下面的代码: Button dropdown
我有一个表格,我希望它直接位于 Logo 下方位于页面中间。到目前为止,我似乎做不到更有什者。任何帮助将不胜感激。谢谢。 这是 HTML 代码:
我的 web 应用程序在与 jQuery Mobile 和 cordova 的聊天部分出现问题。我决定用 textaera 和发送消息的按钮修复页脚。但是当我触摸文本区域写消息时,我的键盘没有出现。我
我有两个来回箭头,可以单击它们在我的单页网站上的框架中浏览照片。我的术语在这里可能不正确。保存照片和前后箭头的 div 出现在我的屏幕下方,而不是在屏幕场景 div 中。我可以将图像向上移动以出现在屏
我使用自定义 CSS 和 Bootstrap 类名称构建了这个 header 。我已经尝试了 z-index、float: initial 属性。提前致谢 .branding-preview {
我有两个部分介绍网站上的用例和好处。如下。 .onboardmessaging { min-width: 100%; } .onboardmessagingwrap { min-wi
所以,我在网站上发现了这个很酷的 css/html slider ,所以我下载了代码,并打算研究它。我已经开始根据自己的需要对其进行编辑和设计,然后我遇到了这个问题:当我添加比原始尺寸更大的图像时,导
我是一名优秀的程序员,十分优秀!