gpt4 book ai didi

android - 如何防止 View 超出 CardView 的圆角?

转载 作者:太空狗 更新时间:2023-10-29 16:10:43 25 4
gpt4 key购买 nike

这是 XML:

<android.support.v7.widget.CardView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginBottom="24dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="24dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="24dp"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="2dp" app:cardCornerRadius="16dp">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView10"
android:layout_weight="2"/>

<TextView
android:text="Bids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView11"
android:layout_weight="1"
android:background="#ea6464"
android:gravity="center_vertical|center_horizontal"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="@android:color/white"/>
</LinearLayout>

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

这是它最终的样子:

not rounded :(

如何将 TextView/LinearLayout 塞到角落里,使其不突出?

最佳答案

就像我在评论区说的。

您可以在底部创建一个带有圆角的可绘制对象,然后将其设置为背景。

这是我称之为 rounded.xml 的形状:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#e56067"/>

<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>

<corners android:radius="1dp"
android:bottomRightRadius="16dp"
android:bottomLeftRadius="16dp"/>

</shape>

然后将布局更改为:

<android.support.v7.widget.CardView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="16dp"
app:cardElevation="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView" />

<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rounded.xml"
android:gravity="center_vertical|center_horizontal"
android:text="Bids"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>

结果如下所示:

enter image description here

关于android - 如何防止 View 超出 CardView 的圆角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53455446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com