【问题标题】:CardView inside TableLayoutTableLayout 内的 CardView
【发布时间】:2015-08-05 00:07:42
【问题描述】:

我在表格布局中有 2 个卡片视图。 代码:

                <TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*"
                    android:layout_height="fill_parent" android:layout_width="fill_parent"
                    android:layout_centerInParent="true"
                    android:layout_below="@+id/card_view3"
                    android:layout_marginTop="7dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp">
                <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:layout_weight="1">

                    <android.support.v7.widget.CardView
                        android:layout_margin="5dp" android:layout_weight="1"
                        android:layout_height="180dp" android:layout_width="fill_parent"
                        android:background="#ffdbff3d">


       </android.support.v7.widget.CardView>

     <android.support.v7.widget.CardView
          android:layout_margin="5dp" android:layout_weight="1"
               android:layout_height="180dp" android:layout_width="fill_parent"
       android:background="#ffdbff3d">


       </android.support.v7.widget.CardView>

     </TableRow>
      </TableLayout>

在 cv1 中有一张图片,问题是当我将图片(在 cv1 中)宽度设置为 fill_parent 时,图片占据了所有行并且不会只填充 cv1,即使我没有设置填充父级,它也能完成它的工作!

我什至无法为我的简历设置背景,我也不知道为什么。

希望你能解决。

【问题讨论】:

  • 不要使用表格布局——只是一个建议
  • 那我可以用什么代替? @ViktorYakunin
  • 如果你要问一个问题,请至少格式化你的代码。

标签: android tablelayout


【解决方案1】:

不需要使用 TableLayout,它的性能很差。解决方案:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="180dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#ffdbff3d" />

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="180dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#ffdbff3d" />
</LinearLayout>

更糟糕的是 - 如果您使用重量而不是指定它会影响的属性,在这种特殊情况下是 layout_width,因此您应该将其设置为 "0dp"

【讨论】:

  • 我认为你不需要指定它会影响哪个属性,它由Linearlayout的方向决定。
猜你喜欢
  • 1970-01-01
  • 2011-07-30
  • 2013-03-23
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
相关资源
最近更新 更多