【问题标题】:How to include a CardView in a home screen widget如何在主屏幕小部件中包含 CardView
【发布时间】:2016-12-31 23:08:49
【问题描述】:

我正在尝试构建一个带有多个时钟(不同区域)的简单主屏幕小部件。设计方面,我想使用 CardView(例如 google 搜索栏)作为根布局元素,但由于它在小部件中不受支持,我该如何复制它?我可以以某种方式使用它的父类,即框架布局吗?

【问题讨论】:

  • 我刚刚尝试使用android.support.v7.widget.CardView,它显示Problem loading widget。我想这仍然是一个限制。奇怪!

标签: android android-view android-cardview android-framelayout home-screen-widget


【解决方案1】:

您可以使用支持的视图类并将背景可绘制对象设置为此处定义的 card_drawable:

https://gist.github.com/MarsVard/8297976

例如,到一个LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="8dp"
              >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/card_drawable"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Test"
            />
        </LinearLayout>
</LinearLayout>

【讨论】:

  • 啊自定义形状。完美运行,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-22
  • 2022-09-27
相关资源
最近更新 更多