Android控件CardView實(shí)現(xiàn)卡片布局
CardView介紹
CardView是Android 5.0系統(tǒng)引入的控件,相當(dāng)于FragmentLayout布局控件然后添加圓角及陰影的效果;CardView被包裝為一種布局,并且經(jīng)常在ListView和RecyclerView的Item布局中,作為一種容器使用。CardView應(yīng)該被使用在顯示層次性的內(nèi)容時(shí);在顯示列表或網(wǎng)格時(shí)更應(yīng)該被選擇,因?yàn)檫@些邊緣可以使得用戶更容易去區(qū)分這些內(nèi)容。
使用
先看效果

首先在build.gradle文件添加依賴庫(kù)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
}
布局文件main.html文件下
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="100dp"> <ImageView android:layout_width="150dp" android:layout_height="match_parent" android:layout_margin="5dp" android:scaleType="centerCrop" android:src="@drawable/sng" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="棒冰行動(dòng)" android:textSize="18sp" android:textStyle="bold" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="棒冰行動(dòng),公益?zhèn)鞑ピO(shè)計(jì)夏令營(yíng)" /> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> </LinearLayout>
在MainActivity.java下文件
public class MainActivity extends AppCompatActivity {
private CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cardView = (CardView)findViewById(R.id.cardView);
cardView.setRadius(8);//設(shè)置圖片圓角的半徑大小
cardView.setCardElevation(8);//設(shè)置陰影部分大小
cardView.setContentPadding(5,5,5,5);//設(shè)置圖片距離陰影大小
}
}
好,已結(jié)束CardView難度不大,當(dāng)是實(shí)用性及及效果是非常棒的,值得你擁有!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android控件CardView實(shí)現(xiàn)卡片效果
- Android使用CardView實(shí)現(xiàn)圓角對(duì)話框
- Android CardView+ViewPager實(shí)現(xiàn)ViewPager翻頁(yè)動(dòng)畫的方法
- Android使用CardView作為RecyclerView的Item并實(shí)現(xiàn)拖拽和左滑刪除
- Android CardView詳解及使用方法和實(shí)例
- Android中使用CircleImageView和Cardview制作圓形頭像的方法
- Android應(yīng)用開發(fā)中CardView的初步使用指南
- Android MaterialCardView的使用介紹與示例
相關(guān)文章
Android利用ViewPager實(shí)現(xiàn)帶小圓球的圖片滑動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android利用ViewPager實(shí)現(xiàn)帶小圓球的圖片滑動(dòng),并且只有第一次安裝app時(shí)才出現(xiàn)歡迎界面具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11
android開發(fā)教程之獲取power_profile.xml文件的方法(android運(yùn)行時(shí)能耗值)
在Android手機(jī)中,對(duì)于手機(jī)中的每個(gè)部件(cpu、led、gps、3g等等)運(yùn)行時(shí)對(duì)應(yīng)的能耗值都放在power_profile.xml文件中2014-02-02
Flutter質(zhì)感設(shè)計(jì)之直接輸入
這篇文章主要為大家詳細(xì)介紹了Flutter質(zhì)感設(shè)計(jì)之直接輸入,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
android控件實(shí)現(xiàn)單擊拖動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了android控件實(shí)現(xiàn)單擊拖動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
TextInputLayout輸入框控件的懸浮標(biāo)簽
這篇文章主要為大家詳細(xì)介紹了TextInputLayout輸入框控件的懸浮標(biāo)簽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
android ItemTouchHelper實(shí)現(xiàn)可拖拽和側(cè)滑的列表的示例代碼
本篇文章主要介紹了ItemTouchHelper實(shí)現(xiàn)可拖拽和側(cè)滑的列表的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
Android解析JSON格式數(shù)據(jù)的兩種方式(JSONObject和Gson)
json數(shù)據(jù)的解析相對(duì)而言,還是比較容易的,實(shí)現(xiàn)的代碼也十分簡(jiǎn)單,下面這篇文章主要給大家介紹了關(guān)于Android解析JSON格式數(shù)據(jù)的兩種方式,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
Android實(shí)現(xiàn)評(píng)論欄隨Recyclerview滑動(dòng)左右移動(dòng)
這篇文章主要介紹了Android實(shí)現(xiàn)評(píng)論欄隨Recyclerview滑動(dòng)左右移動(dòng)效果,仿約會(huì)吧應(yīng)用詳情頁(yè)實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2016-05-05
OpenGL ES透視投影實(shí)現(xiàn)方法(四)
這篇文章主要為大家詳細(xì)介紹了OpenGL ES透視投影的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05

