2014-12-01 47 views
0

我一直在爲我的一個小項目使用CardView兼容性庫。更多問題與新CardView的背景

所有都很好用我所有的設備,

當我紛紛亮出前幾天我的Nexus 7與Android 5圖像時除外。

這是結果我得到

  • BEFORE(原料藥低於21)

enter image description here

  • (在Nexus 7同一個品牌新的閃存Android 5)

enter image description here

是否有人有線索?




這是我使用的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/cardlayout" 
android:layout_width="320dp" 
android:layout_height="130dp" 
android:background="@android:color/transparent" 
android:orientation="vertical" 
android:paddingBottom="5dp" 
android:paddingRight="5dp" 
> 

<FrameLayout 
    android:layout_width="320dp" 
    android:layout_height="117dp" > 

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     card_view:cardBackgroundColor="@android:color/transparent" 
     android:foreground="@android:color/transparent" 
     card_view:cardCornerRadius="@dimen/radius" 
     card_view:cardElevation="@dimen/elevation" > 

     <LinearLayout 
      android:orientation="horizontal" 
      android:id="@+id/ll" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/my_foreground_selector" 
      android:padding="@dimen/elevation" > 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 

    <LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="320dp" 
     android:layout_height="117dp" 
     android:orientation="horizontal" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_margin="4dp" 
      android:gravity="center" > 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@drawable/abc_menu_dropdown_panel_holo_light" 
       android:gravity="center" 
       android:padding="10dp" > 

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

        <ImageView 
         android:id="@+id/image" 
         android:layout_width="96dp" 
         android:layout_height="96dp" 
         android:layout_gravity="center" 
         android:gravity="center" 
         android:src="@drawable/gelato_na_nb" /> 

        <TextView 
         android:id="@+id/image_not_available" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:gravity="center" 
         android:text="@string/image_loading" 
         android:textAppearance="?android:attr/textAppearanceSmall" 
         android:textColor="#7A7A7A" 
         android:textStyle="bold" /> 

        <ProgressBar 
         android:id="@+id/progress" 
         style="@android:style/Widget.ProgressBar.Inverse" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:gravity="center" 
         android:indeterminateDrawable="@anim/progress_dialog_anim" 
         android:textAppearance="?android:attr/textAppearanceSmall" /> 
       </RelativeLayout> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:gravity="center_vertical" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:gravity="left" 
       android:text="TextView" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#795548" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/address" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:gravity="left" 
       android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextView" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#ff5722" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/ratinglabel" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:gravity="left" 
        android:text="@string/rating" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#ffc107" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/filler" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:gravity="left" 
        android:text=" " 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/rating" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:gravity="left" 
        android:text="@string/rating" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#ffc107" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/filler2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:gravity="left" 
        android:text=" " 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <RatingBar 
        android:id="@+id/ratingbar" 
        style="?android:attr/ratingBarStyleSmall" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
      </LinearLayout> 

      <TextView 
       android:id="@+id/open" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:gravity="left" 
       android:text="TextView" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="@color/green" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 



</LinearLayout> 

這是我的選擇my_foreground_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" 
android:exitFadeDuration="@android:integer/config_mediumAnimTime"> 

<item android:state_pressed="true" 

    android:drawable="@drawable/my_foregound_pressed"/> 
<item android:drawable="@drawable/my_foregound_unpressed"/> 
</selector> 

這是我的選擇my_foregound_pressed.xml

<?xml version="1.0" encoding="UTF-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:left="@dimen/padding" 
    android:right="@dimen/padding" 
    android:bottom="@dimen/padding" 
    android:top="@dimen/padding"> 

    <shape android:shape="rectangle"> 
     <solid android:color="@color/card_pressed"/> 
     <corners android:radius="@dimen/radius"/> 


    </shape> 
</item> 
</layer-list> 

這是我的選擇my_foregound_unpressed.xml

<?xml version="1.0" encoding="UTF-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:left="@dimen/padding" 
    android:right="@dimen/padding" 
    android:bottom="@dimen/padding" 
    android:top="@dimen/padding"> 

    <shape android:shape="rectangle"> 
     <solid android:color="@android:color/white"/> 
     <corners android:radius="@dimen/radius"/> 


    </shape> 
</item> 
</layer-list> 

回答

1

在棒棒糖新高程屬性擡起指定視圖達到一定的z值,其可以任何其它它定位在您在XML中指定的視圖,無論它們是否進一步「縮減」您的層次結構。

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <View 
     android:elevation="5dp" 
     .... /> 

    <!-- This view will be positioned under the above, 
     one, even though it is defined further down 
     layout file --> 
    <View 
     android:elevation="0dp" 
     ... /> 

</FrameLayout> 

因此,要在你的卡上面的內容,無論是海拔等量的設置爲你的LinearLayout使用id =「@ + ID /佈局」,或把它你CardView內。

+0

這可能是真的!我會盡力接受你回答! – 2014-12-04 18:16:49