[英]Create rounded corners on View
有沒有什么方法可以在LinearLayout
內部創建View
圓角而不是使用shape
?
<View
android:layout_width="48dp"
android:clickable="true"
android:layout_height="48dp"
android:background="#f55151" />
您可以使用CardView,並且可以在cardview中創建自己的視圖。 在CardView上,您可以設置card_view:cardCornerRadius。
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/yourColor"
card_view:cardCornerRadius="6dp">
<View
android:layout_width="48dp"
android:clickable="true"
android:layout_height="48dp"
android:background="#f55151" />
</androidx.cardview.widget.CardView>
如果您不想使用CardCard形狀,這是最簡單的方法:有關更多詳細信息,請參閱官方文檔
首先將此行添加到您的依賴項中:
implementation 'com.android.support:cardview-v7:28.0.0'
然后像這樣使用它:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.