【发布时间】:2017-02-28 11:38:27
【问题描述】:
我需要把上面的ImageView放在Cardview前面。当我将CardView 的颜色设为透明时,ImageView 在前面,但CardView 应该是白色的。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Background -->
<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<ScrollView
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="240dp"
android:scrollbars="none">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="32dp"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
card_view:contentPadding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:orientation="vertical">
...
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginRight="32dp"
android:src="@drawable/ic_gallery"
fab:fab_colorNormal="@color/accent"
fab:fab_colorPressed="@color/accent"
fab:fab_colorRipple="@android:color/white" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="top|left"
android:scaleType="center"
android:layout_marginLeft="32dp"
tools:src="@drawable/profile" />
</FrameLayout>
</ScrollView>
</FrameLayout>
【问题讨论】:
-
在滚动条结束标签后添加ImageView..
-
你作为父级使用的是FrameLayout,添加在顶部的项目将显示在顶部。
-
@MohammedAtif 进行更正,您最后添加的项目将显示在 UI 的顶层/顶层。
-
您的代码已经按照您的意愿运行了...我什至尝试了您的代码,它运行良好。
-
@KamranAhmed 不要与框架布局和相对布局混淆。您所说的内容适用于相对布局。
标签: android xml material-design