2017-02-28 59 views
-1

我需要在Cardview之前得到上面的ImageView。當我使CardView顏色透明時,ImageView位於前面,但CardView應爲白色。如何在CardView前獲取ImageView?

enter image description here

<?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> 
+0

添加ImageView的... –

+0

你什麼正在使用作爲父項的FrameLayout,添加在頂部的項目將顯示在頂部。 –

+0

@MohammedAtif進行更正,最後添加的項目將顯示在用戶界面的頂層/頂層。 –

回答

1

你可以試試這個佈局

<?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> 

希望這有助於你以某種方式....滾動條的結束標記之後