gpt4 book ai didi

android - 如何在android中制作圆角半径

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:41 25 4
gpt4 key购买 nike

我正在尝试制作一个 gridview,它下面有一个图像和文本,具有角半径效果。到目前为止,这似乎是不可能的。这是我的 Activity xml,它包含 gridview:

<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnWidth="140dp"
android:padding="5dp"
android:layout_marginTop="10dp"
android:numColumns="auto_fit"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</ScrollView>

这是适配器 xml:

<?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:orientation="vertical"
android:layout_height="wrap_content"
android:padding="2dp"
android:layout_margin="20dp"
android:background="@drawable/grid_corner_radius"
android:layout_width="wrap_content">
<ImageView
android:layout_width="200dp"
android:background="@drawable/cat_life"
android:layout_height="160dp"/>

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:id="@+id/credit_textView"
android:gravity="center"
android:text="Life"
android:textColor="#FFFFFF"
android:background="@color/colorPrimary"
android:textSize="15dp"/>
</LinearLayout>

最后是角半径魔术代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#C0C0C0"></solid>
<corners android:radius="15dp"></corners>
</shape>
</item>
</selector>

输出如下:

enter image description here

看到图像的尖锐矩形边缘是可见的。可能的解决方案是什么?

最佳答案

您可以使用 CardView 封装您的适配器 xml 并为其设置 cornerRadius。它应该可以工作。

compile 'com.android.support:cardview-v7:24.2.0' 添加到您的应用程序 gradle 文件中。

<android.support.v7.widget.CardView xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:card_view="https://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:layout_margin="20dp"
card_view:cardCornerRadius="4dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:layout_width="200dp"
android:background="@drawable/cat_life"
android:layout_height="160dp"/>

<TextView
android:layout_width="200dp"
android:layout_height="40dp"
android:id="@+id/credit_textView"
android:gravity="center"
android:text="Life"
android:textColor="#FFFFFF"
android:background="@color/colorPrimary"
android:textSize="15dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>

关于android - 如何在android中制作圆角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45391643/

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