2017-06-05 1 views
0

私は何かが欠けているように感じますが、これを理解できないようです。だから私はCardViewの上に色の小さなストリップを作ってみたいですが、フレームレイアウトやあらゆる種類のレイアウトを使って背景色を設定すると、CardViewの丸みのあるコーナーが覆い隠されます。ここにいくつかのコードとその問題のスクリーンショットがあります。早めにありがとう!丸みのあるコーナーを維持しながら、Android CardViewのトップの色を表示

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dp" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
card_view:cardCornerRadius="10dp"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="16dp" 
    android:layout_gravity="end" 
    android:background="@color/colorPrimaryDark" 
    android:clipChildren="true"/> 

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

    <ImageView 
     android:id="@+id/menuCardImage" 
     android:layout_width="128dp" 
     android:layout_height="128dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:layout_margin="8dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_margin="8dp" 
     android:layout_toRightOf="@+id/menuCardImage" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/menuCardName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="32sp" 
      android:textStyle="bold" /> 

    </LinearLayout> 

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

issue image

編集: が、それはアンドロイドスタジオでちょうど表示の問題だったが判明。私はアプリをインストールすると正しく動作しました。

+0

カードビューでは、android:backgroundTint = "@ color/colorPrimary"を試してください。または、cardview corner-radiusと同じコーナー半径を持つシェイプドロアブルを作成し、ビューのbgとして設定してください。 – Debu

+0

これは、ロリポップのみ? – Zielony

答えて

0

背景を色として設定するのではなく、このドロアブルを使用して背景を設定します。

top_strip.xmldrawableフォルダに作成します。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:topLeftRadius="10dp" 
     android:topRightRadius="10dp"/> 
    <solid android:color="#FFffffff"/> 
</shape> 

半径をカードコーナー半径と同じに設定し、必要に応じて色を変更します。それは動作します

関連する問題