【问题标题】:Make android layout child wider than parent?使android布局子比父更宽?
【发布时间】:2019-03-19 18:43:45
【问题描述】:

我的代码是:

<?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="match_parent"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="#00ff00"/>
</android.support.v7.widget.CardView>

我的输出是 我想要绿色视图以匹配整个屏幕父宽度。 这可能吗? 我想使用卡片视图作为父视图,因为它会有高度。

【问题讨论】:

  • 只需从您的父视图中删除这两行...android:layout_marginLeft="30dp" android:layout_marginRight="30dp"
  • @GowthamanM 的想法是在父母身上有边距,在孩子身上没有
  • 从逻辑上思考它会如何发生..child 将根据父属性执行..

标签: android layout cardview


【解决方案1】:

这是你的解决方案...

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        />
    <View
        android:id="@+id/fab"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_centerVertical="true"
        android:background="#00ff00"
        />
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 1970-01-01
    • 2016-03-20
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多