我是 Android 新手,这是我在这里的第一个问题。
我正在尝试在卡片视图的开头添加彩色垂直边框。如何在 xml 上实现它?我尝试用空的文本视图添加它,但它弄乱了整个卡片视图本身。例如,请检查下面发布的图片链接。
activity_main.xml
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:contentPadding="16dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/Base.TextAppearance.AppCompat.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
style="@style/Base.TextAppearance.AppCompat.Body1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Content here" />
</LinearLayout>
</android.support.v7.widget.CardView>
非常感谢
原文由 George Forster 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试做:
这会从卡片视图中删除填充并添加带有颜色的 FrameLayout。然后,您需要修复 LinearLayout 中的填充,然后修复其他字段
更新
如果要保留卡片角半径,请在可绘制文件夹中创建 card_edge.xml:
并在框架布局中使用
android:background="@drawable/card_edge"