Android 如何获取CardView前面的ImageView?
我需要在Android 如何获取CardView前面的ImageView?,android,xml,material-design,Android,Xml,Material Design,我需要在cardwiew前面获取上面的ImageView。当我将cardwiew颜色设置为透明时,ImageView位于前面,但cardwiew应为白色 ... 您可以尝试此布局 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.an
cardwiew
前面获取上面的ImageView
。当我将cardwiew
颜色设置为透明时,ImageView
位于前面,但cardwiew
应为白色
...
您可以尝试此布局
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardViewId"
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:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
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" />
</FrameLayout>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:scaleType="center"
tools:src="@drawable/profile" />
</RelativeLayout>
</ScrollView>
</FrameLayout>
希望这对您有所帮助….在关闭滚动条标记后添加ImageView..您使用的是FrameLayout作为父对象,添加在顶部的项目将显示在顶部。@MohammedAtif为了更正,您最后添加的项目将显示在UI的顶部/前端层。您的代码已经按照您的要求工作了。。。我甚至试过你的代码,它工作得很好。@KamranAhmed不要把框架布局和相对布局搞混了。你所说的对相对布局有好处。
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardViewId"
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:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
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" />
</FrameLayout>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:scaleType="center"
tools:src="@drawable/profile" />
</RelativeLayout>
</ScrollView>
</FrameLayout>