溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android中怎么利用CardView控件實現卡片效果

發布時間:2021-06-26 16:39:44 來源:億速云 閱讀:320 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關Android中怎么利用CardView控件實現卡片效果,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

1.添加依賴

implementation 'com.android.support:cardview-v7:25.3.1'

2.主界面設置一些卡片的屬性:

package com.example.admin.ztest; import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.support.v7.widget.CardView;/*app:cardBackgroundColor這是設置背景顏色 app:cardCornerRadius這是設置圓角大小 app:cardElevation這是設置z軸的陰影 app:cardMaxElevation這是設置z軸的最大高度值 app:cardUseCompatPadding是否使用CompatPadding app:cardPreventCornerOverlap是否使用PreventCornerOverlap app:contentPadding 設置內容的padding app:contentPaddingLeft 設置內容的左padding app:contentPaddingTop 設置內容的上padding app:contentPaddingRight 設置內容的右padding app:contentPaddingBottom 設置內容的底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);//設置圖片圓角的半徑大小    cardView.setCardElevation(8);//設置陰影部分大小    cardView.setContentPadding(5, 5, 5, 5);//設置圖片距離陰影大小  }}

布局頁面:

<?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="電池編號"          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>

看完上述內容,你們對Android中怎么利用CardView控件實現卡片效果有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女