我正在尝试制作一个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./apk/res/android"
xmlns:app="http://schemas./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./apk/res/android">
<item>
<shape xmlns:android="http://schemas./apk/res/android" >
<solid android:color="#C0C0C0"></solid>
<corners android:radius="15dp"></corners>
</shape>
</item>
</selector>
输出如下:
看到图像的锐利矩形边缘是可见的.可能的解决方案是什么? 解决方法: 您可以使用CardView封装适配器xml并将cornerRadius设置为它.它应该可以工作.
将编译’com.android.support:cardview-v7:24.2.0’添加到您的应用程序gradle文件中.
<android.support.v7.widget.CardView xmlns:android="https://schemas./apk/res/android"
xmlns:card_view="https://schemas./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./apk/res/android"
xmlns:app="http://schemas./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>
来源:https://www./content-4-403251.html
|