【问题标题】:How to make Relative layout look like CardView [closed]如何使相对布局看起来像 CardView [关闭]
【发布时间】:2015-11-18 04:41:14
【问题描述】:

我有太多的相对布局,我想将它转换为它看起来像卡片。我如何制作看起来像卡片的可绘制对象。我想让它变成像一行一样的矩形形状。

【问题讨论】:

  • 为什么不用CardView 包裹你的相关布局?
  • 我尝试换行,但我的旧项目中有太多 xml,因此可能会影响我的布局对齐

标签: android android-layout android-xml android-relativelayout


【解决方案1】:

试试这个:

     <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
        android:paddingRight="15dp"
        android:background="@drawable/card_background"
        android:descendantFocusability="afterDescendants" />

制作一个名为card_background.xml的drawable:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB" />
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>

【讨论】:

    【解决方案2】:

    为相对布局添加背景:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB" />
            <corners android:radius="2px" />
        </shape>
    </item>
    
    <item
        android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/grey" />
            <corners android:radius="2px" />
        </shape>
    </item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 2011-01-23
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      相关资源
      最近更新 更多