Android控件CardView實(shí)現(xiàn)卡片效果
這是android新推出的一個(gè),讓卡片帶立體感的一個(gè)控件,就是一個(gè)卡牌,有點(diǎn)類似于布局那種的東西,里面可以添加控件內(nèi)容
先看看運(yùn)行的效果圖:
1.添加依賴
implementation 'com.android.support:cardview-v7:25.3.1'
2.主界面設(shè)置一些卡片的屬性:
package com.example.admin.ztest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.CardView; /* app:cardBackgroundColor這是設(shè)置背景顏色 app:cardCornerRadius這是設(shè)置圓角大小 app:cardElevation這是設(shè)置z軸的陰影 app:cardMaxElevation這是設(shè)置z軸的最大高度值 app:cardUseCompatPadding是否使用CompatPadding app:cardPreventCornerOverlap是否使用PreventCornerOverlap app:contentPadding 設(shè)置內(nèi)容的padding app:contentPaddingLeft 設(shè)置內(nèi)容的左padding app:contentPaddingTop 設(shè)置內(nèi)容的上padding app:contentPaddingRight 設(shè)置內(nèi)容的右padding app:contentPaddingBottom 設(shè)置內(nèi)容的底padding */ public class MainActivity extends AppCompatActivity { CardView cardView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); cardView = (CardView) findViewById(R.id.cardView); cardView.setRadius(8);//設(shè)置圖片圓角的半徑大小 cardView.setCardElevation(8);//設(shè)置陰影部分大小 cardView.setContentPadding(5, 5, 5, 5);//設(shè)置圖片距離陰影大小 } }
布局頁(yè)面:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" app:cardCornerRadius="8dp"> <LinearLayout android:layout_width="600pt" android:layout_height="100pt" android:background="@drawable/bg_battery_detail" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:background="#184467"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="horizontal"> <TextView android:id="@+id/tvBatteryNo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="電池編號(hào)" android:textColor="@color/color_z2" android:textSize="20sp" /> <TextView android:id="@+id/tvBatterySlotNo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15pt" android:text="@string/app_name" android:textColor="@color/white" android:textSize="20sp" /> </LinearLayout> <ImageView android:id="@+id/ivCloseDialog" android:layout_width="39pt" android:layout_height="39pt" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="8pt" android:padding="7pt" android:src="@mipmap/popup_del" /> </RelativeLayout> </LinearLayout> </android.support.v7.widget.CardView>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android使用CardView實(shí)現(xiàn)圓角對(duì)話框
- Android控件CardView實(shí)現(xiàn)卡片布局
- Android CardView+ViewPager實(shí)現(xiàn)ViewPager翻頁(yè)動(dòng)畫(huà)的方法
- Android使用CardView作為RecyclerView的Item并實(shí)現(xiàn)拖拽和左滑刪除
- Android CardView詳解及使用方法和實(shí)例
- Android中使用CircleImageView和Cardview制作圓形頭像的方法
- Android應(yīng)用開(kāi)發(fā)中CardView的初步使用指南
- Android MaterialCardView的使用介紹與示例
相關(guān)文章
Android手勢(shì)密碼view學(xué)習(xí)筆記(一)
這篇文章主要為大家詳細(xì)介紹了Android手勢(shì)密碼view的學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Android實(shí)現(xiàn)ViewPage輪播圖效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)ViewPage輪播圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Android編程獲取包名,版本信息及VersionName名稱的方法
這篇文章主要介紹了Android編程獲取包名,版本信息及VersionName名稱的方法,涉及Android包及版本相關(guān)操作函數(shù)使用技巧,需要的朋友可以參考下2016-10-10Android獲取網(wǎng)絡(luò)連接狀態(tài)新方法整理
這篇文章主要給大家介紹了關(guān)于Android獲取網(wǎng)絡(luò)連接狀態(tài)新方法的相關(guān)資料,在開(kāi)發(fā)安卓移動(dòng)端時(shí)幾乎每一個(gè)app都需要連接網(wǎng)絡(luò),因此對(duì)設(shè)備的網(wǎng)絡(luò)狀態(tài)檢測(cè)是很有必要的,需要的朋友可以參考下2023-11-11Android實(shí)現(xiàn)閱讀APP平移翻頁(yè)效果
這篇文章主要介紹了Android實(shí)現(xiàn)閱讀APP平移翻頁(yè)效果的具體方法,模仿多看閱讀平移翻頁(yè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03分享Android 藍(lán)牙4.0(ble)開(kāi)發(fā)的解決方案
這篇文章主要為大家分享了Android 藍(lán)牙4.0(ble)開(kāi)發(fā)的解決方案,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03Android Studio 3.5版本JNI生成SO文件詳解
這篇文章主要介紹了Android Studio 3.5版本JNI生成SO文件詳解,想了解JNI的同學(xué),可以參考下2021-04-04Android實(shí)現(xiàn)CoverFlow效果控件的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)CoverFlow效果控件的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05