国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android控件CardView實(shí)現(xiàn)卡片布局

2019-10-21 21:37:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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)容。

使用

先看效果

Android,控件,CardView,卡片布局

首先在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í)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 台州市| 米脂县| 新河县| 古浪县| 巨鹿县| 鹿邑县| 浦城县| 区。| 安阳市| 锦州市| 阿坝县| 离岛区| 宁化县| 云霄县| 湾仔区| 什邡市| 尉氏县| 阿鲁科尔沁旗| 富阳市| 乐昌市| 崇州市| 台安县| 上饶市| 方城县| 青龙| 龙口市| 嘉兴市| 新绛县| 阳山县| 赤水市| 泰安市| 阳西县| 江油市| 建瓯市| 大兴区| 龙川县| 龙川县| 彝良县| 镇巴县| 呼玛县| 衡阳县|