【发布时间】:2016-03-01 15:27:32
【问题描述】:
我有一个包含两个视图的聊天屏幕:一个用于显示以前聊天的回收器视图和一个包含编辑文本的自定义视图、一个发送按钮和另一个回收器视图,让用户选择其他要发送的内容,例如照片等. 这个自定义视图被称为“面板”。
所以,我的聊天活动有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<chat.example.app.widget.Panel
style="@style/PanelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:id="@+id/panel" />
<android.support.v7.widget.RecyclerView
android:background="@android:color/holo_red_dark"
android:layout_margin="@dimen/activity_horizontal_margin"
android:scrollbars="vertical"
android:id="@+id/previous_chat"
android:layout_above="@id/panel"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
我的“面板”视图具有以下布局:
<?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="wrap_content"
android:background="@android:color/white">
<RelativeLayout
android:id="@+id/staging_area_root"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Chat box and send -->
</RelativeLayout>
<!-- THIS GUY IS PROBLEMATIC -->
<android.support.v7.widget.RecyclerView
android:id="@+id/card_set"
android:layout_margin="15dp"
android:layout_below="@id/staging_area_root"
android:background="@android:color/holo_blue_bright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
问题是来自Panel 的回收器视图吞噬了整个屏幕空间。所以我所看到的只是来自 Panel 类的有问题的回收者视图。
这两个回收站视图都分配了LinearLayoutManagers。 还没有适配器。
我的build.gradle 中有最新的支持库:
compile 'com.android.support:recyclerview-v7:23.2.0'
并阅读最新的 android 开发者博客文章:
此版本为 LayoutManager API 带来了令人兴奋的新功能: 自动测量!这允许 RecyclerView 根据 其内容的大小。这意味着以前不可用 场景,例如将 WRAP_CONTENT 用于 RecyclerView,现在都可以了。你会发现所有内置 LayoutManagers 现在支持自动测量。
我错过了什么吗?
更新 1:
我向有问题的回收站先生视图添加了一个适配器,其中包含 0 个项目。仍然没有解决办法。
更新 2:
截图:
【问题讨论】:
-
不要在
Panel上使用android:layout_gravity,而是使用android:layout_alignParentBottom和android:layout_centerHorizontal。我复制粘贴了您的布局,删除了Panelxml 并将其替换为它的布局 xml,并且在 Android Studio 的预览中一切正常。 -
@AlexTownsend 运气不好。作为更新,我 am 使用
alignParentBottom。这里还没有更新代码。也许这与我的自定义视图的创建方式有关? -
您能否发布 Android Studio 中的预览屏幕截图或设备/模拟器的屏幕截图?
-
@AlexTownsend 你想要哪个截图?与你要求我改变的属性? :)
-
@AlexTownsend 完成。蓝色recyclerview来自
Panel。
标签: android android-support-library android-recyclerview