Android Studio:线性布局不可见

时间:2019-02-10 13:33:32

标签: android android-layout android-linearlayout

我的应用程序中的相对布局下面有一个线性布局。这些包含在“约束”布局和“滚动视图”中。

不幸的是,我的线性布局之一没有出现在屏幕上。

下面是我的代码,为了使内容更清楚,我删除了一些内容,例如TextViews。

<?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=".ViewSingleClub">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="444dp"
        android:layout_marginTop="68dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:layout_editor_absoluteX="4dp"
            tools:layout_editor_absoluteY="68dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@drawable/gradientsbackground"
                android:orientation="vertical"
                android:gravity="center"
                android:visibility="visible">

               //items inside here

            </LinearLayout>

            <android.support.v7.widget.CardView
                android:layout_width="270dp"
                android:layout_height="100dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="100dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:weightSum="4">

                    //items inside here

                </LinearLayout>
            </android.support.v7.widget.CardView>
        </RelativeLayout>


//This layout and everything inside doesn't appear

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="45dp"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                //items inside here
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

有人可以帮我弄清楚为什么看不到此线性布局吗?

1 个答案:

答案 0 :(得分:0)

尝试此方法可以解决您的问题

<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">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="444dp"
    android:layout_marginTop="68dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:layout_editor_absoluteX="4dp"
            tools:layout_editor_absoluteY="68dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@drawable/gradientsbackground"
                android:gravity="center"
                android:orientation="vertical"
                android:visibility="visible">

                //items inside here

            </LinearLayout>

            <android.support.v7.widget.CardView
                android:layout_width="270dp"
                android:layout_height="100dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="100dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:weightSum="4">

                    //items inside here

                </LinearLayout>
            </android.support.v7.widget.CardView>
        </RelativeLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="45dp"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                //items inside here

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</ScrollView>