第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

MaterialDesign學(xué)習(xí)篇(七),CardView卡片式布局的使用

標(biāo)簽:
Android

什么是CardView

CardView顾名思义就是一个卡片型的View,它是在Android5.0引入的一个控件,作为一个容器使用,它本身继承于FrameLayout,可以说它的使用和FrameLayout差不多,也是用来包裹一些子View,只不过它可以添加圆角和阴影的效果,经常在ListView或RecyclerView的item布局中作为容器使用,使内容看起来更加突出和显眼。

如何使用CardView

先看下效果,未使用CardView时:

使用CardView时的效果:

导入依赖

    compile 'com.android.support:cardview-v7:26.0.0-alpha1'

布局文件中,使用CardView

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            app:contentPadding="5dp"
            app:cardElevation="5dp"
            app:cardCornerRadius="5dp"
            >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >

            <ImageView
                android:layout_width="150dp"
                android:layout_height="100dp"
                android:background="@mipmap/book"
                />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_marginLeft="5dp"
                android:padding="5dp"
                >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="特战先驱"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="战争是血淋淋的,战争是实实在在的,战争中的每一个军人都是有血有肉的。本小说恰恰注重于战术层面和细节问题,通过一个个有血有肉的军人,演绎出一段段可歌可泣的具体的战争故事!"
                    android:textSize="14sp"
                    android:lines="4"
                    android:ellipsize="end"
                    android:layout_marginTop="5dp"
                    />

            </LinearLayout>

        </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

和使用FrameLayout一样,直接用CardView作为容器包裹,其中app:contentPadding="5dp"指定了卡片内容于边距的间隔为5dp,app:cardElevation="5dp"指定了卡片阴影的大小为5dp,app:cardCornerRadius="5dp"指定了卡片的圆角大小为5dp。是不是看起来有种卡片的形状,相比没有添加CardView,是不是显得比较好看。

CardView的一些属性说明

   属性                             说明

cardBackgroundColor              卡片的背景颜色

cardCornerRadius                 卡片的圆角大小

cardElevation                    阴影的大小

cardMaxElevation                 阴影最大高度

cardUseCompatPadding             设置内边距,V21+的版本和之前的版本仍旧具有一样的计算方式

cardPreventCornerOverlap         在V20和之前的版本中添加内边距,这个属性为了防止内容和边角的重叠

contentPadding                   卡片内容于边距的间隔

contentPaddingTop                卡片内容与顶部的边距

contentPaddingBottom             卡片内容与底部的边距

contentPaddingLeft               卡片内容与左边的边距

contentPaddingRight              卡片内容与右边的边距 

本文对CardView做了简单的介绍,并演示了它的效果,需要源码的可以查看:

https://github.com/chaychan/MaterialDesignExercise

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開發(fā)工程師
手記
粉絲
62
獲贊與收藏
487

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消