【问题标题】:Card View layout_height="wrap_content" inside scroll view not working滚动视图中的卡片视图 layout_height="wrap_content" 不起作用
【发布时间】:2016-06-17 23:22:28
【问题描述】:

我在滚动视图和卡片视图中添加了卡片视图我添加了偏好片段,但它只显示偏好类别标题。

setting.xml

<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.afollestad.appthemeengine.inflation.ATEToolbar
    android:id="@+id/toolbar"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view"
    android:layout_below="@+id/toolbar">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="4dp"
            style="?attr/CardTheme" />
    </RelativeLayout>
</ScrollView>
</RelativeLayout>

任何解决方案。

【问题讨论】:

  • 请发布您的片段 xml。
  • 您的卡片视图的高度为“wrap_content”。所以它包装了卡片。在卡片内添加项目。

标签: android scrollview android-cardview


【解决方案1】:

添加android:fillViewport="true" 填充滚动视图。也不要忘记更改滚动视图内相对布局的高度。将其更改为 match_parent 和卡片视图的高度(match_parent)。

最后布局应该是这样的,

<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.afollestad.appthemeengine.inflation.ATEToolbar
    android:id="@+id/toolbar"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view"
    android:fillViewport="true"
    android:layout_below="@+id/toolbar">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardElevation="4dp"
            style="?attr/CardTheme" />
    </RelativeLayout>
</ScrollView>
</RelativeLayout>

【讨论】:

  • Thnx..我会试试的。
猜你喜欢
  • 1970-01-01
  • 2019-04-04
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
  • 1970-01-01
  • 2017-07-09
  • 1970-01-01
相关资源
最近更新 更多