2017-07-31 5 views
0

カードビューを使用していますが、標高とカードビューのプロパティがバージョン5.0以下で動作していません。カードビューがLollipopバージョンの下で動作しない

私は、いくつかのSOの投稿を検索してcard_view:cardUseCompatPadding = "true"を使用しようとしましたが、これも機能しませんでした。

それはこの

enter image description here

のようになります。そして、それはレイアウトです。ここ4.2.2

enter image description here

に次のようになります。

<android.support.v7.widget.CardView 
    xmlns:app="http://schemas.android.com/tools" 
    android:id="@+id/card_view" 
    app:cardUseCompatPadding="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="05dp" 
    android:layout_marginTop="05dp" 
    card_view:cardElevation="12dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:background="@color/bg"> 

     <View 
      android:layout_width="3dp" 
      android:layout_height="match_parent" 
      android:background="@color/cardLineColor"></View> 

     <LinearLayout 
      android:id="@+id/linearLayout6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginEnd="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginStart="10dp" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/txt_id" 
       android:layout_width="103dp" 
       android:layout_height="wrap_content" 
       android:text="ID" 
       android:textColor="@color/white" /> 

      <TextView 
       android:id="@+id/txt_date" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="05dp" 
       android:text="23/3/2015" 
       android:textColor="@color/textColor" 
       android:textSize="10sp" /> 


     </LinearLayout> 

     <TextView 
      android:id="@+id/txt_trans_type" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/linearLayout6" 
      android:layout_centerHorizontal="true" 
      android:text="sent money" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:id="@+id/linearLayout8" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignTop="@+id/linearLayout6" 
      android:layout_marginEnd="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginStart="10dp" 
      android:layout_toEndOf="@+id/txt_trans_type" 
      android:layout_toRightOf="@+id/txt_trans_type" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/txt_balance" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="end" 
       android:text="$3214" 
       android:textAlignment="viewEnd" 
       android:textColor="@color/white" 
       android:textStyle="bold" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="end" 
       android:layout_marginTop="05dp" 
       android:text="@string/balance" 
       android:textAlignment="viewEnd" 
       android:textColor="@color/white" 
       android:textSize="10sp" /> 

     </LinearLayout> 
    </RelativeLayout> 

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

編集:Iこのような9パッチファイルを作成しました

enter image description here

しかし、これは、このエラーを与えている:

Error:Some file crunching failed, see logs for details 
Error:Execution failed for task ':app:mergeDebugResources'. 
> Error: Some file crunching failed, see logs for details 

は、その高さ幅がはるかにあることができますか?私は小さな高さの幅で試しましたが、それからいくらかのギャップを残します。どのようにすべてのデバイスに一致させることができますか?

+0

少なくともこの標高の高さが機能しているかどうかを知るのは難しいですが、少なくとも私は違いは見えません。それにもかかわらず、 'cardElevation'プロパティは、ロリポップ前のデバイスにも有効です。それ以外の場合は 'backgroundColor'を' RelativeLayout'ではなく 'cardBackgroundColor'を介して' CardView'に直接定義する必要があります。 – reVerse

+0

私はapp:cardBackgroundColor = "@color/bg"を使って背景を定義しようとしましたが、まだ白を表示しています。 @reVerse – Sid

+0

私はちょうどあなたのレイアウトと私の推奨事項でそれをテストし、私はドロップレベルと私のAPIレベル19エミュレータで白い環境を持っていない - すべてがうまくいくようです。 – reVerse

答えて

0

悲しいことに、あなたがそれを言ったように、仰角はAPI 19以下では利用できません。

私の似たような問題を解決するために、私のカードビューを通常のレイアウトで置き換え、背景として9パッチイメージを使用して影を生成します。非常にモダブルな利点があります。さらに、エレベーションプロパティとは異なり、シンプルな黒い影を必要としない場合は、シャドウカラーのようなカスタマイズが可能です。

唯一の問題は、自分でイメージをデザインしてプロジェクトに追加する必要があることです。しかし、恐れていない、あなたのためにそれを生成することができるthis oneのようないくつかの便利なジェネレータがあります。レイアウトよりも小さい最小サイズを設定して、変形せずにフィットすることを確認してください。私は通常、10×10ピクセルの幅の画像を生成し、はるかに大きな視野に適用しても影は変形しません。

イメージを取得したら(名前はmyimage.9.pngのようになります)、.9.png拡張子を削除せずに単純にドロウアブルに追加してレイアウトに通常のバックグラウンド描画可能に設定します、XMLまたはコードを介して。そして、あなたは終わった!

EDIT:あなたはまた、cardviewの上に照明があることに気づかなかった。あなたがPhotoshopのようなものを持っているならば、暗いものにドロップシャドウを適用して9パッチを作成し、もう1つのドロップシャドウを追加するために2番目のレイヤーを作成しますが、今回は白に設定し、適切な角度で上に表示します。次に、それをpngとして保存し、9パッチジェネレータを使用して.9.png画像に変換します。

See the 9-patch documentation here. Androidスタジオを使用している場合は、9パッチ用の内蔵ジェネレータもあります。

悲しいことに、Material DesignがAndroid 5にステップインする前に、ぼんやりとした表示のためにユーザーインターフェイスが少し制限されていました。たぶん、あなたはプログラムであなたのcardviewsを追加することができますので、あなたのユーザーのほとんどは、あなたの希望cardviewsを持っていますが、それはすぐにあなたが必要な場合は、必要のあるコードの量を増やすことができる方法この

if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.LOLLIPOP){ 
    //Add regular layout to your views with 9 patch 
} else{ 
    //Add cardview to get desired effect 
} 

ような何かを行うことができますクリック可能/ドラッグ可能な要素など。

+0

私は試みましたが、私は同じ画像の背景を作ることができませんでした。線量は良く見えません。 :-( – Sid

+0

編集された答えを参照してください。でも、前もってロリポップデバイスのような高度な見た目を得ることは難しいでしょう。 – YumeYume

+0

編集した質問を確認してください。 – Sid

0

card_view:cardElevation="12dp" の代わりにapp:cardElevation="12dp" を使用してください。

+0

助けてくれません... – Sid

+0

アプリを削除しようとしました:cardUseCompatPadding = "true" –

+0

は役に立たなかった。 – Sid

関連する問題