【问题标题】:How to Create RecycleView with custom Shape?如何使用自定义形状创建 RecyclerView?
【发布时间】:2019-04-27 18:18:06
【问题描述】:

我用这样的自定义形状制作了一个 RecycleView,但我发现很难在左右两侧制作一个半圆。我应该在 .xml 文件中添加什么?

【问题讨论】:

  • 看起来像用作背景的图像。
  • 您可以使用的背景图片...尝试使用 9 补丁图片
  • 您可以使用一张图像并根据您的情况更改图像颜色。
  • 您可以使用任何图像或查看此库以获取自定义视图github.com/vipulasri/TicketView

标签: android android-studio android-recyclerview android-cardview shapes


【解决方案1】:

您可以将此布局用作您的行

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardCornerRadius="10dp"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"

        >
   <View
       android:layout_width="20dp"
       android:layout_height="20dp"
       android:layout_gravity="center"
       android:layout_marginStart="-10dp"
       android:background="@drawable/shape_example_circle"
       />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >
`enter code here`Make your view here
    </RelativeLayout>
        <View
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_gravity="center"
            android:layout_marginEnd="-10dp"
            android:background="@drawable/shape_example_circle"
            />
    </LinearLayout>
</android.support.v7.widget.CardView>

小圆可绘制

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    >
<size android:height="@dimen/dp_20"
    android:width="@dimen/dp_20"/>
    <solid android:color="@color/greyish"/>

</shape>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多