繁体   English   中英

布局相同,手机上的显示不同

[英]Same Layout, Different Display on Phones

我正在Nexus 6和第二代Motorola G上测试我的应用程序。 我有一个混合了cardviews和recyclerviews的布局。 一个recyclerview特别是从lorem ipsum生成器从后台加载数据,并应该显示10个刷新。 在Motorola G上,它可以正常显示,但在Nexus 6上而不是10个结果上,它只能显示一个,在左边是联系6,在右边是可以正确显示所有内容的Motorola:

这是两个电话都使用的布局:

<?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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM