2015-11-20 10 views
6

में cardview से अधिक दृश्य बनाने मैं इस लेआउट
enter image description hereएंड्रॉयड

यह एक cardview (ग्रे दृश्य) और imageView (नीला दृश्य) उस के लिए मैं इस कोड का उपयोग है बनाना चाहते हैं

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/abc_search_url_text_normal" 
android:orientation="vertical"> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="bottom" 
    android:layout_marginBottom="3dp" 
    android:paddingTop="5dp" 
    app:cardBackgroundColor="@color/abc_input_method_navigation_guard"> 


</android.support.v7.widget.CardView> 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_gravity="bottom" 
    android:layout_marginBottom="30dp" 
    android:layout_marginRight="10dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/abc_ratingbar_full_material" /> 

</FrameLayout> 

लेकिन नतीजतन मेरी छवि दृश्य कार्डव्यू के पीछे जा रहा है, मैं framelayout के बजाय reletivelayout कोशिश करें लेकिन एक ही परिणाम।

उत्तर

5

प्रयास करें:

  • एक RelativeLayout

  • का उपयोग माता पिता सही/समाप्त करने के लिए imageView संरेखित और एक सही/अंत मार्जिन

  • संरेखित के शीर्ष करने के फैब जोड़ने कार्ड व्यू और नकारात्मक मार्जिन जोड़ें


<RelativeLayout 
    ...> 
    <CardView 
    android:id="@+id/cardView" 
    android:layout_width="match_parent" 
    android:layout_height="120dp" 
    /> 

    <ImageView 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@id/cardView" 
    android:layout_marginTop="-32dp" 
    android:layout_marginRight="20dp" 
    /> 

</RelativeLayout> 
+0

आप @cw लेकिन वहाँ एक्सएमएल – max

+0

में करने के लिए एक तरह से मैं अपने जवाब –

+0

नवीनीकृत किया है मैं ऐसा है धन्यवाद भी, लेकिन दिलचस्प चीजें यहां है जो कार्डव्यू के साथ काम नहीं करती है, मैं इसे किसी अन्य प्रकार के दृश्य और काम से पहले करता हूं लेकिन कार्डव्यू – max

11

CardView एपीआई 21+ में डिफ़ॉल्ट ऊंचाई से है, तो आप ऊंचाई में हेरफेर imageView की तुलना में कम हो सकता है

<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardElevation="1dp"/> 

<ImageView 
     android:id="@+id/image_view_user" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:elevation="2dp"/> 

पूर्व 21 में आप उपयोग कर सकते

overlayView.bringToFront(); 
root.requestLayout(); 
root.invalidate(); 

इस 21+ में काम नहीं करेगा यदि आप अलग अलग ऊंचाई है

1

बस अन्य दृश्य ली में CardView डाल फ्रेमलेआउट में के। बस नीचे दिए गए की तरह:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_marginStart="10sp" 
android:layout_marginEnd="10sp" 
> 
<FrameLayout 
    android:layout_marginTop="15sp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="100sp" 
     app:cardCornerRadius="5sp" 
     app:cardBackgroundColor="@color/colorPrimary"> 
    <!--other view items --> 
    </android.support.v7.widget.CardView> 
</FrameLayout> 
    <de.hdodenhof.circleimageview.CircleImageView 
     android:layout_width="90sp" 
     android:layout_height="90sp" 
     app:civ_border_width="2dp" 
     android:layout_marginStart="10sp" 
     app:civ_border_color="@color/colorPrimaryDark" 
     android:id="@+id/profileImg" 
     android:background="@drawable/ic_if_profle_1055000" 
     xmlns:app="http://schemas.android.com/apk/res-auto"/> 

स्क्रीनशॉट:

Image over CardView