2015-10-21 41 views
0

我創建了一個回收視圖,但它顯示不乾淨的android棒棒糖。 但在lolipop它不顯示兩卡之間的線。 這裏是我的佈局回收視圖顯示差異在Android棒棒糖

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rvproduct" 
    android:layout_weight="9" 
    android:layout_width="match_parent" 
    android:layout_height="0dp"> 
</android.support.v7.widget.RecyclerView> 

和Cardview佈局:

<android.support.v7.widget.CardView 
     android:id="@+id/cvsp" 
     card_view:cardUseCompatPadding="true" 
     android:layout_width="match_parent" 
     android:layout_height="90dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="horizontal" 
      android:layout_height="match_parent" 
      android:background="@color/white" 
      android:padding="8dp" 
      android:weightSum="7" 
      > 

      <ImageView 
       android:id="@+id/product_photo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:background="@null" 
       android:layout_gravity="center_vertical|center_horizontal" 
       android:layout_alignParentTop="true" 
       android:layout_weight="1" 
       android:src="@drawable/logodms" /> 

      <LinearLayout 
       android:id="@+id/liner" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_toRightOf="@+id/product_photo" 
       android:background="@color/white" 
       android:layout_weight="4" 
       android:orientation="vertical" 
       android:weightSum="4" 
       android:layout_alignParentBottom="true" 
       > 

       <TextView 
        android:id="@+id/product_name" 
        android:layout_width="match_parent" 
        android:background="@color/white" 
        android:layout_height="0dp" 
        android:layout_alignParentTop="true" 
        android:layout_weight="1" 
        android:text="Vitamin Messi" 
        android:textColor="@color/colorPrimary" 

        android:textColorHighlight="@color/colorPrimaryDark" 
        android:textStyle="bold" /> 
       <TextView 
        android:id="@+id/product_unitprice" 
        android:layout_width="wrap_content" 
        android:background="@color/white" 
        android:layout_height="0dp" 
        android:layout_below="@+id/product_name" 
        android:layout_weight="1" 
        android:text="4.000/LE 10.000/CHAN" 
        android:textColor="@color/colorPrimaryDark" 
        android:textColorHighlight="@color/colorPrimary" 
        android:textStyle="italic" /> 

       <TextView 
        android:id="@+id/product_saleunitofmeasure" 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:background="@color/white" 
        android:layout_below="@+id/product_name" 
        android:layout_weight="1" 
        android:text="Hộp" 
        android:textStyle="italic" /> 
       <TextView 
        android:id="@+id/product_No" 
        android:layout_width="match_parent" 
        android:background="@color/white" 
        android:layout_height="0dp" 
        android:layout_alignParentTop="true" 
        android:layout_weight="1" 
        android:textSize="10dp" 
        android:textStyle="bold" /> 

      </LinearLayout> 
      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:background="@color/white" 
       android:orientation="vertical" 
       android:weightSum="3" 
       android:layout_height="match_parent"> 
       <TextView 
        android:layout_weight="1" 
        android:background="@color/white" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:text="Số lượng" 
        android:textStyle="bold" 
        android:textSize="10dp" 
        android:textColor="@color/colorPrimary" 
        android:id="@+id/textView7" 
        android:gravity="center_vertical|center_horizontal" /> 

       <TextView 
        android:id="@+id/product_tonkho" 
        android:background="@color/white" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 

        android:textSize="15dp" 
        android:textColor="@color/black" 
        android:textStyle="bold" 
        android:gravity="center_vertical|center_horizontal" 
        /> 
       <TextView 
        android:id="@+id/product_chietkhau" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@color/white" 
        android:textSize="10dp" 
        android:textColor="@color/green" 
        android:textStyle="bold" 
        android:gravity="center_vertical|center_horizontal" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentEnd="true" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 

看看這裏的Android 4.4和Android 5.0

的是Android 4.4: Look so cool 的是Android 5.0: So bad

回答

0

嘗試添加attr CardElevation來CardView。例如:

<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:layout_width="match_parent" 
android:layout_height="wrap_content" 
card_view:cardCornerRadius="0dp" 
card_view:cardElevation="1dp"> 

你可能更喜歡使用ItemDecoration項目之間添加間距。例如:

public class SpaceItemDecoration extends RecyclerView.ItemDecoration { 
private int space; 

public SpaceItemDecoration(int space) { 
    this.space = space; 
} 

@Override 
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 
    outRect.left = space; 
    outRect.right = space; 
    outRect.bottom = space; 

    if(parent.getChildPosition(view) == 0) 
     outRect.top = space; 
} 

和:

yourRecycleView.addItemDecoration(new SpaceItemDecoration(3)); 

P/S:我知道 「臺島DJA大公HOA旺國貿有限公司XANH」 ;-)

+0

我嘗試這一點,但沒有改變:(你知道「臺島DJA大公HOA旺國貿有限公司XANH。」哦,太好了,你是從哪裏來的? – AndroidLTG

+0

我從上,這使得這部影片的地方來的。不幸的是,沒有chat-c​​hit :(。快樂編碼! –

1

我今天有這個問題。

我簡單地爲我的LinearLayout包裝添加了一個邊距。您的父級單元格是CardView,因此請嘗試爲其添加邊距。你不會得到相同的「卡」外觀,但它看起來像細胞,它很有吸引力。

但是,我建議您始終將Linear/RelativeLayout作爲基本單元。原因是因爲使用Linear/RelativeLayout包裝器可以讓孩子更容易對齊。

<android.support.v7.widget.CardView 
    android:id="@+id/cvsp" 
    card_view:cardUseCompatPadding="true" 
    android:layout_width="match_parent" 
    android:layout_height="90dp" 
    android:layout_margin="5dp"> 
+0

不錯!請upvote,如果可以!:) – liyicky

+0

是啊。Upvote for you! – AndroidLTG