【问题标题】:ListView not shown where layout is too tall布局太高的地方未显示 ListView
【发布时间】:2018-02-25 21:04:36
【问题描述】:

所以我试图在 android 中为我一直在做的社交网络创建一个前端,但由于某种原因,当照片是正方形时,我的 cmets 的 ListView 没有显示。我看到如果照片更小,所有 cmets 都会显示,因此它为 cmets 留出了一些空间,但列表视图会堆叠在下一个视图下或只是不显示。

父RecyclerView是

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.wonerwhy.oddy.smps.helper.Posts">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvItems"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
     android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tvUsername"
        android:layout_width="269dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/ivAvatar"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/ivAvatar"
        android:layout_width="60dp"
        android:layout_height="60dp"

        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/ivPost"
        android:layout_width="match_parent"
        android:minHeight="100dp"
        android:layout_height="wrap_content"
         android:layout_marginTop="8dp"
        android:adjustViewBounds="true"
        android:cropToPadding="true"

        android:scaleType="fitCenter"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ivAvatar"
        app:srcCompat="@mipmap/ic_launcher" />

    <ListView
        android:orientation="vertical"
        android:id="@+id/lvComments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ivPost"
        />
</android.support.constraint.ConstraintLayout>

接下来是列表视图中的项目

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="81dp">

    <TextView
        android:id="@+id/tvUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tvComment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/tvUser"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

帖子有很多如左图所示的cmets,但android应用无法显示它们

如果比例小于 1:1

【问题讨论】:

    标签: android android-layout listview android-recyclerview


    【解决方案1】:

    如果有人遇到同样的问题: 我发现将 ListView 嵌套到 RecyclerView 中,同时在包装内容上的布局高度会自动将其缩小到 0,我认为即使我想使用列表视图,滚动也会被 RecyclerView 滚动覆盖,所以我放弃了 ListView(稍后见)。 相反,我使用了 LinearLayout 并将其填充到 RecyclerView 的 onBindViewHolder 方法中。

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 2021-06-03
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      相关资源
      最近更新 更多