[英]Grid Layout Isn't Showing in Android Fragment
I want to create some 4 grid layout which is have Constraint Layout as a root layout. 我想创建一些具有约束布局作为根布局的4网格布局。 The file is created to be as a fragment, but I think that won't be a problem, mentioned in title to describe it as detail as possible.
该文件被创建为一个片段,但我认为这不是问题,如标题所述,以尽可能详细地描述它。
The xml file is looked like this: 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>
And it should be looked like this ( screenshot taken from Android Studio preview ) 它应该看起来像这样( 截图来自Android Studio预览 )
But the output in the real device the Grid layout is not showing. 但是实际设备的输出未显示Grid布局。 Is there a thing I miss?
我有想念的东西吗?
#Note: The rest layout is showed just fine no problem, only the GridLayout. #注意:剩下的布局显示就好了,没问题,只有GridLayout。
Please set the height and width of the GridLayout, where you didn't define, please copy and paste the code as it is which is given below it will definitely work. 请设置您未定义的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>
implementation 'com.android.support:support-v4:28.0.0'
implementation'com.android.support:design:28.0.0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.