Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
网格布局不是';t在Android片段中显示_Android_Android Layout_Android Fragments - Fatal编程技术网

网格布局不是';t在Android片段中显示

网格布局不是';t在Android片段中显示,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我想创建一些4个网格布局,它将约束布局作为根布局。该文件被创建为一个片段,但我认为这不会是一个问题,在标题中提到要尽可能详细地描述它 xml文件如下所示: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http

我想创建一些4个网格布局,它将约束布局作为根布局。该文件被创建为一个片段,但我认为这不会是一个问题,在标题中提到要尽可能详细地描述它

xml文件如下所示:

<?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"
    android:background="@color/colorPrimaryLight"
    tools:context=".view.LoanDetail">

<View
    android:id="@+id/divider_loan"
    android:layout_width="match_parent"
    android:layout_height="3dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/line_white"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:weightSum="2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/divider_loan">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center">

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:drawableEnd="@drawable/ic_money_outl"
            android:drawablePadding="@dimen/margin16"
            android:gravity="center"
            android:text="Total Pinjaman"
            android:textColor="@color/white" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="start|center_vertical"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_currency_dep"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginEnd="@dimen/margin8"
            android:gravity="center|clip_vertical"
            android:text="IDR"
            android:textColor="@color/white"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/TEXTVIEW"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginEnd="@dimen/margin8"
            android:gravity="center_vertical"
            android:text="100,000,000"
            android:textColor="@color/white"
            android:textSize="18sp" />

    </LinearLayout>
</LinearLayout>


    <GridLayout
    android:id="@+id/gridLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="@dimen/margin16"
    android:alignmentMode="alignMargins"
    android:columnCount="2"
    android:columnOrderPreserved="false"
    android:padding="@dimen/margin8"
    android:rowCount="2"
    app:layout_constraintBottom_toTopOf="@+id/linearLayout4"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:layout_marginStart="@dimen/margin8"
        android:layout_marginEnd="@dimen/margin8"
        android:layout_marginBottom="@dimen/margin8"
        app:cardCornerRadius="@dimen/margin8"
        app:cardElevation="@dimen/margin8">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingStart="@dimen/margin8"
            android:paddingTop="@dimen/margin16"
            android:paddingEnd="@dimen/margin8"
            android:paddingBottom="@dimen/margin8">

            <TextView
                android:id="@+id/textView7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Pokok"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin24"
                android:text="IDR"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tv_loan_det_prim"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin8"
                android:layout_marginTop="@dimen/margin8"
                android:text="100,000,000"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="18sp" />

        </LinearLayout>

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

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:layout_marginStart="@dimen/margin8"
        android:layout_marginEnd="@dimen/margin8"
        android:layout_marginBottom="@dimen/margin8"
        app:cardCornerRadius="@dimen/margin8"
        app:cardElevation="@dimen/margin8">

        <LinearLayout
            android:id="@+id/rel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingStart="@dimen/margin8"
            android:paddingTop="@dimen/margin16"
            android:paddingEnd="@dimen/margin8"
            android:paddingBottom="@dimen/margin8">

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

                <TextView
                    android:id="@+id/textView14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Angsuran"
                    android:textColor="@color/black" />

                <TextView
                    android:id="@+id/textView15"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/margin8"
                    android:layout_marginEnd="@dimen/margin8"
                    android:text="TERTUNGGAK"
                    android:textColor="@color/colorAccent"
                    android:textSize="10sp" />

            </LinearLayout>

            <TextView
                android:id="@+id/textView16"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin24"
                android:text="IDR"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/textView17"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin8"
                android:layout_marginTop="@dimen/margin8"
                android:text="500,000"
                android:textColor="@color/colorAccent"
                android:textSize="18sp" />

            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:layout_marginStart="@dimen/margin8"
                android:layout_marginTop="@dimen/margin8"
                android:layout_marginEnd="@dimen/margin8"
                android:background="@drawable/bg_green_primary"
                android:text="BAYARAN"
                android:textColor="@color/white" />
        </LinearLayout>

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

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:layout_marginStart="@dimen/margin8"
        android:layout_marginEnd="@dimen/margin8"
        android:layout_marginBottom="@dimen/margin8"
        app:cardCornerRadius="@dimen/margin8"
        app:cardElevation="@dimen/margin8">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingStart="@dimen/margin8"
            android:paddingTop="@dimen/margin16"
            android:paddingEnd="@dimen/margin8"
            android:paddingBottom="@dimen/margin8">

            <TextView
                android:id="@+id/textView18"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Sisa Plafon"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/textView19"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin24"
                android:text="IDR"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/textView20"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin8"
                android:layout_marginTop="@dimen/margin8"
                android:text="9,500,000"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="18sp" />

        </LinearLayout>

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

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:layout_marginStart="@dimen/margin8"
        android:layout_marginEnd="@dimen/margin8"
        android:layout_marginBottom="@dimen/margin8"
        app:cardCornerRadius="@dimen/margin8"
        app:cardElevation="@dimen/margin8">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:orientation="vertical"
            android:paddingStart="@dimen/margin8"
            android:paddingTop="@dimen/margin16"
            android:paddingEnd="@dimen/margin8"
            android:paddingBottom="@dimen/margin8">

            <TextView
                android:id="@+id/textView21"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Tenor/Bunga Bulanan"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/textView22"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin8"
                android:layout_marginTop="@dimen/margin24"
                android:text="12 / 0.50%"
                android:textColor="@color/colorPrimaryLight"
                android:textSize="18sp" />
        </LinearLayout>

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

</GridLayout>

<LinearLayout
    android:id="@+id/linearLayout4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="16dp"
    android:background="@drawable/bg_green_dark"
    android:orientation="horizontal"
    android:padding="@dimen/margin16"
    android:weightSum="4"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent">

    <TextView
        android:id="@+id/textView9"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableTop="@drawable/ic_list_inactive"
        android:gravity="center"
        android:text="Senarai Simpanan"
        android:textColor="@color/grey_inactive" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:clickable="true"
        android:drawableTop="@drawable/ic_apps"
        android:focusable="true"
        android:gravity="center"
        android:text="Detil"
        android:textColor="@color/white" />

    <TextView
        android:id="@+id/textView11"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawableTop="@drawable/ic_history_inactive"
        android:gravity="center"
        android:text="Transaksi"
        android:textColor="@color/grey_inactive" />

    <TextView
        android:id="@+id/textView13"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawableTop="@drawable/ic_pen_inactive"
        android:gravity="center"
        android:text="Aplikasi Baru"
        android:textColor="@color/grey_inactive" />
</LinearLayout>

</android.support.constraint.ConstraintLayout>

但实际设备中的输出网格布局未显示。 有什么我错过的吗


#注意:rest布局显示得很好,没有问题,只有GridLayout。

请设置GridLayout的高度和宽度,在您没有定义的地方,请复制并粘贴下面给出的代码,它肯定会工作

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <GridLayout
        android:id="@+id/gridLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:alignmentMode="alignMargins"
        android:columnCount="2"
        android:columnOrderPreserved="false"
        android:rowCount="2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:ignore="MissingConstraints">
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
           >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
             >
                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Pokok"
                    android:textColor="@color/black" />
                <TextView
                    android:id="@+id/textView12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="IDR"
                    android:textSize="12sp" />
                <TextView
                    android:id="@+id/tv_loan_det_prim"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="100,000,000"
                    android:textSize="18sp" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
          >
            <LinearLayout
                android:id="@+id/rel"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
              >
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <TextView
                        android:id="@+id/textView14"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Angsuran"
                        android:textColor="@color/black" />
                    <TextView
                        android:id="@+id/textView15"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="TERTUNGGAK"
                        android:textColor="@color/colorAccent"
                        android:textSize="10sp" />
                </LinearLayout>
                <TextView
                    android:id="@+id/textView16"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="IDR"
                    android:textSize="12sp" />
                <TextView
                    android:id="@+id/textView17"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="500,000"
                    android:textColor="@color/colorAccent"
                    android:textSize="18sp" />
                <Button
                    android:id="@+id/button"
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:text="BAYARAN"
                    android:textColor="@color/white" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"

          >
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
               >
                <TextView
                    android:id="@+id/textView18"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sisa Plafon"
                    android:textColor="@color/black" />
                <TextView
                    android:id="@+id/textView19"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="IDR"
                    android:textSize="12sp" />
                <TextView
                    android:id="@+id/textView20"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="9,500,000"

                    android:textSize="18sp" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
         >
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_rowWeight="1"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/textView21"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Tenor/Bunga Bulanan"
                    android:textColor="@color/black" />
                <TextView
                    android:id="@+id/textView22"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="12 / 0.50%"
                    android:textSize="18sp" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
    </GridLayout>
</android.support.constraint.ConstraintLayout>


您是否可以根据编码共享设计外观?如果您可以共享完整的xml,您已经对布局“linearLayout3”和“linearLayout4”进行了引用,但未找到这些引用。@nikk已经更新了它sir@MuhammadFaisal我没有发现任何问题。我登记了真实设备。。向我显示网格布局。
匹配父项
没有帮助,先生。。说到这里,我使用的根布局是约束布局,我使用了
match\u Constraint
使其取决于什么约束,所以它会自动变成0dp。。如果我将其更改为匹配\u parent,则布局的约束溢出了DHMM有什么问题吗。。你检查过了吗?我更新了帖子?请只设置gridLayout的高度和宽度。嗯,我无法用文字解释,所以这是使用0dp,这是使用你的答案,先生,在真实设备上运行?怎么可能,我的坏了。无论如何,我已经实现了这两个依赖项。是的,它在真正的设备上工作,你能告诉我你在哪台设备上运行和你的Api级别吗?我使用三星J,在Api级别21的Lolipop上运行。。这与网格布局有关吗?
  implementation 'com.android.support:support-v4:28.0.0'
  implementation'com.android.support:design:28.0.0'