在android中實現CardView
android在 5.0中添加了陰影效果主要通過CardView來實現,在低版本中通過android.support.v7.widget.CardView來實現。
<RelativeLayout xmlns:android="<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardBackgroundColor="@android:color/white" app:cardCornerRadius="3dp" app:cardElevation="2dp" app:cardUseCompatPadding="true" ></pre><br />
可以看到上面的代碼中多了三個app:屬性,cardCornerRadius設置圓角大小,app:cardElevation設置陰影大小,最需要注意的屬性是cardUseCompatPadding,它在5.0以下的系統中默認是true,但在5.0系統中默認為false,如果不設置 app:cardUseCompatPadding=”true”的話會造成在5.0系統的Android手機上不能看到陰影效果。
最后一定要記得加上xmlns:app="
順便附上CardView的兼容lib(eclipse可用)http://download.csdn.net/detail/zhong1113/8707351
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!