2015-07-25 22 views
13

Tôi đang gặp một số sự cố với tính năng minh bạch CardView và card_elevation. Cố gắng sử dụng một CardView minh bạch kết quả là:Android CardView với đường viền kỳ lạ khi trong suốt

enter image description here

Nếu không minh bạch:

enter image description here

Những gì tôi đang cố gắng để có được một cái gì đó như thế này:

enter image description here

Đây là xml của tôi:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="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:background="@mipmap/eifell" 
    android:padding="10dp" 
    tools:context=".MainActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="5dp" 
     android:background="@android:color/transparent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.CardView 
       android:id="@+id/newsCardView" 
       android:layout_width="match_parent" 
       android:layout_height="175dp" 
       card_view:cardBackgroundColor="#602B608A" 
       card_view:cardElevation="5dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@android:color/transparent"> 
       </LinearLayout> 

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

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 
+1

Bạn đã bao giờ nhận được một workaround cho điều này? Có vẻ như các thẻ không được thiết kế để hỗ trợ độ trong suốt của nền: https://code.google.com/p/android/issues/detail?id=78061 –

+1

Xin chào Steve, không, tôi chỉ sử dụng RelativeLayout với nền trong suốt mà không cần bóng (độ cao). Khi tôi tìm thấy một cái gì đó tôi sẽ đăng ở đâu. – cRobot

+0

@SteveBlackwell Đó là câu trả lời hợp lệ của câu hỏi này. Cảm ơn. –

Trả lời

5

Hãy thử mã này:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/newsCardView" 
     android:layout_width="175dp" 
     android:layout_height="175dp" 
     card_view:cardBackgroundColor="#602B608A" 
     card_view:cardCornerRadius="0dp" 
     card_view:cardElevation="5dp"> 

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:layout_gravity="left|top" 
     android:src="@drawable/fake_image" /> //REPLACE THIS WITH YOUR IMAGE 
</FrameLayout> 

enter image description here

Nếu nó không giúp, cung cấp mã xml toàn bộ bố trí của bạn

+0

Mọi thứ đều tuyệt vời trên thiết bị của tôi, hãy thử cập nhật thư viện cardView thành com.android.support:cardview-v7:22.1.1 –

+0

Tôi đang sử dụng phiên bản này, bạn đã thử nghiệm phiên bản Android nào? – cRobot

+0

Android 4.4.2 và Android 5.1.1 –

Các vấn đề liên quan