android - 如何在android中的视图上重叠imageview
问题描述
我是Android的初学者。我想做这个。
但我不知道怎么做……我的是这个
我想ImageView
在 line() 上重叠 bus( View
)。
这是我的代码...
activity_main.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_margin="30dp"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabLayout"/>
<ImageView
android:id="@+id/busImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@+id/tabLayout"
android:src="@drawable/ic_directions_bus_24dp"/>
</RelativeLayout>
activity_custom.xml
<?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="match_parent"
android:orientation="horizontal"
android:weightSum="8">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2">
<View
android:id="@+id/line1"
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:background="@color/colorDS"/>
<View
android:id="@+id/line2"
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:background="@color/colorDS"/>
</RelativeLayout>
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="6">
<TextView
android:id="@+id/stNm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"/>
<TextView
android:id="@+id/arsId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/stNm"
android:textSize="13dp"/>
</RelativeLayout>
</LinearLayout>
解决方案
您可以使用 RecyclerView 实现此布局。您需要将总线图像放在 RecyclerView 的每个项目中并相应地处理可见性。
这是 RecyclerView 的项目布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:id="@+id/line1"
android:layout_width="5dp"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
android:background="#ff0000"
android:layout_marginStart="32dp"/>
<TextView
android:id="@+id/stNm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/line1"
android:layout_marginStart="40dp"
android:text="testzczczc"
android:textSize="20dp"/>
<TextView
android:id="@+id/arsId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/line1"
app:layout_constraintTop_toBottomOf="@id/stNm"
android:layout_marginStart="40dp"
android:text="tesdfsfsfsst"
android:textSize="20dp"/>
<ImageView
android:id="@+id/busImage"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/bus"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="@id/line1"
app:layout_constraintEnd_toEndOf="@id/line1"/>
</android.support.constraint.ConstraintLayout>
在这里你需要处理 busImage 的可见性。
推荐阅读
- c++ - 在 pytorch c++ API 中添加填充
- javascript - 当有多个选项卡或窗口时,如何使用 navigator.serviceWorker.onmessage 在本地存储中存储一次数据?
- python - 为什么结果总是在 2.87 左右
- ios - 您如何解决“SDK 版本问题”?
- python - 无法循环通过设备
- angular - 刷新页面时显示找不到页面
- sqoop - Cloudera Sqoop 异常,当它通过 scoop 命令创建作业时
- powerbi - PowerBI 可以用来从多个 SAP-BW 多维数据集生成报告吗?
- kubernetes - 我是否需要在客户端使用 istio sidecar 代理才能应用路由规则?
- java - EmbeddedActiveMQBroker 的依赖关系是什么?