java - 为什么我的桌子没有在我的卡片中滚动?
问题描述
我有一个 recyclerview 有可变数量的卡片。每张卡片代表一顿饭,并有一张桌子,里面有不同数量的食物。我试图让我的表格滚动,但我没有任何运气。
我已经尝试删除除了滚动视图之外的所有内容,为滚动视图赋予不同的权重,无论是否使用 LinearLayout 作为 TableLayout 的父级。没有任何效果。
这是我当前的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="cards main container">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardBackgroundColor="@color/color_white"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="2"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddFood"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
card_view:srcCompat="@android:drawable/ic_input_add" />
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
android:layout_weight="2">
<TableLayout
android:id="@+id/foodTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0079D6">
<TextView
android:id="@+id/tvFood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/dp8"
android:text="@string/food"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/tvQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="@dimen/dp16"
android:text="@string/hashtag"
android:textColor="#FFFFFF" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
在卡片内滚动有什么问题吗?
谢谢您的帮助。
解决方案
你正在使用layout_weight
. 根据父视图的方向使您的子视图的高度/宽度0dp
达到目的。如果您的父视图有两个具有相同权重的子视图,请注意。设置layout_weight
较大的数字没有任何区别。它计算权重之间的值。
- 水平 ->
layout_width="0dp"
垂直->
layout_height="0dp"
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:baselineAligned="false"> <LinearLayout android:layout_width="match_parent" android:layout_weight="2" android:layout_height="0dp" // make it 0 dp android:orientation="vertical"/> <ScrollView android:layout_width="0dp" //it should be 0dp android:layout_height="match_parent" android:isScrollContainer="true" android:layout_weight="2"/>
推荐阅读
- azure - Azure Runbook 重启脚本没有错误
- javascript - 尝试运行“节点”时出现语法错误。我如何解决它?
- reactjs - 如何在 react-syntax-highlighter 中突出显示标记?
- python - Ultisnips:使用单个 ex 命令禁用某些剪辑的选项?
- ios13 - 应用程序图标在 iOS 13 设备上不在屏幕上,无法通过 XCUITest 按下
- django - 使用 DateField 时不保存表单数据
- laravel - 在laravel中使用oracle导入数据到elasticsearch的问题
- java - 为 Bouncy Castle TLS 服务器设置 TLS 连接设置
- css - 防止由 flexbox 布局的居中对齐元素中的文本换行引起的间隙
- r - 如何根据列的内容添加 2 个数据框的大小?