Android MaterialCardView的使用介紹與示例
Android—MaterialCardView的使用

我們的征程是星辰大海,而非人間煙塵
文章目錄 Android---MaterialCardView的使用演示xml布局其他的屬性
演示

xml布局
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView2"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:clickable="true" // 是否可點擊
app:cardCornerRadius="20dp" // 圓角半徑
app:cardElevation="20dp" // 陰影范圍
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner"
app:rippleColor="#A8C0EC" // 點擊陰影特效的顏色
app:state_dragged="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="140dp"
android:scaleType="centerCrop"
android:src="@drawable/quesans" />
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="140dp"
android:text="問答"
android:textColor="@color/black"
android:textFontWeight="@android:integer/config_mediumAnimTime"
android:textSize="18sp" />
</com.google.android.material.card.MaterialCardView>

其他的屬性
| 特征 | 相關(guān)屬性 |
|---|---|
| Border | app:strokeColor app:strokeWidth |
| Checkable | android:checkable |
| Checked Icon | app:checkedIcon app:checkedIconTint |
| Foreground Color | app:cardForegroundColor |
| Ripple Color | app:rippleColor |
當然你還可以在Java/Kotlin代碼中使用一些方法:
void setCheckable (boolean checkable)//設置是否可以選擇 void setChecked (boolean checked)//選中的狀態(tài) void setCheckedIcon (Drawable checkedIcon)//選中圖標的樣式 void setCheckedIconResource (int id)//選中圖標的樣式 void setDragged (boolean dragged)//是否可拖動 void setRippleColor (ColorStateList rippleColor)//波紋效果的顏色 void setStrokeColor (int strokeColor)//卡片邊的顏色 void setStrokeWidth (int strokeWidth)//卡片邊的寬帶 void toggle ()//控制checkable的開關(guān)
到此這篇關(guān)于Android MaterialCardView的使用介紹與示例 的文章就介紹到這了,更多相關(guān)Android MaterialCardView內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
android創(chuàng)建數(shù)據(jù)庫(SQLite)保存圖片示例
這篇文章主要介紹了android創(chuàng)建數(shù)據(jù)庫,保存圖片到數(shù)據(jù)庫再從數(shù)據(jù)庫取圖片的方法,大家參考使用吧2014-01-01
Android中默認系統(tǒng)的聲音/大小修改和配置詳解
這篇文章主要給大家介紹了關(guān)于Android中默認系統(tǒng)的聲音/大小修改和配置的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-11-11
Android中@id和@+id及@android:id的區(qū)別介紹
這篇文章主要給大家介紹了關(guān)于Android中@id和@+id及@android:id的區(qū)別的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-09-09

