android - 相同的布局,不同的手机显示
问题描述
我正在 Nexus 6 和 Motorola G 第二代上测试我的应用程序。我有一个混合了cardviews和recyclerviews的布局。一个 recyclerview 特别是从 lorem ipsum 生成器从后台加载数据,并且应该显示 10 个结果。在摩托罗拉 G 上,它显示正常,但在 Nexus 6 上而不是 10 个结果正确,它只显示一个,左侧是 nexus 6,右侧是摩托罗拉,它正确显示所有内容:
这是用于两部手机的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingBottom="50dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NewsFragments.FeedsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingBottom="10dp"
tools:context=".NewsFragments.FeedsFragment">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="3dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/nav_view"
android:layout_marginStart="9dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:padding="5dp"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
我很困惑为什么一部手机会滚动而另一部不认为它是相同的信息,以及显示相同的布局文件,唯一的区别是手机的大小。
任何有关如何解决此问题的帮助将不胜感激!
解决方案
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingBottom="10dp"
tools:context=".NewsFragments.FeedsFragment"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="3dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp">
<EditText
android:id="@+id/new_post_text"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginBottom="92dp"
android:drawableLeft="@drawable/ic_cow_img"
android:drawablePadding="2dp"
android:ems="10"
android:gravity="start|top"
android:hint="share a status update"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Spinner
android:id="@+id/spinner"
android:layout_width="116dp"
android:layout_height="26dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="32dp"
android:entries="@array/post_preferences"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageButton2"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/button3"
android:layout_width="84dp"
android:layout_height="43dp"
android:layout_marginEnd="12dp"
android:text="Post"
app:layout_constraintBottom_toBottomOf="@+id/spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/spinner"
app:layout_constraintVertical_bias="0.526" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="40dp"
android:layout_height="35dp"
android:background="@null"
android:src="@drawable/ic_image_black_24dp"
tools:layout_editor_absoluteX="112dp"
tools:layout_editor_absoluteY="109dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="3dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:padding="10dp" />
</android.support.v7.widget.CardView>
<!--<android.support.v7.widget.CardView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--app:cardCornerRadius="3dp"-->
<!--app:cardElevation="4dp"-->
<!--app:cardUseCompatPadding="true">-->
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/nav_view"
android:layout_marginStart="9dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:padding="5dp"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:scrollbars="vertical" />
<!--</android.support.v7.widget.CardView>-->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
使它起作用的是将 ScrollView 换成 Nested ScrollView。
推荐阅读
- python - 无法在 Python 3.7 或 Python 3.8 中导入 numpy - Ubuntu 18.04
- r - 在 R 中使用 read_excel 正确解析日期
- r - 如何删除R字符串中的“\”字符?
- swift - Swift 中 NSMutableArray 的排序函数的参数是什么?
- git - 删除损坏的 git 文件
- sql - 分区表中的分区日期范围
- c# - 有没有人有使用 NuGet 的 DocumentFormat.OpenXML.DotNet.Core 包构建控制台应用程序 (C#) 的经验?
- asp.net-web-api2 - 从旧版本中查找新版本 Postman 中的字段
- docker - docker nginx-proxy “坏网关”
- c++ - 在 c++ 程序中按 enter 后,“cin”将提供所有变量