网格布局未真实显示 phone Android
Grid Layout Not Showing In Real phone Android
我正在 GridLayout 中制作卡片视图。我 运行 我的应用程序在我的真实设备上。我的 CardView 不显示
我也在 Whosebug 中检查了这个问题,但这个问题可能与我的代码不同
这是我的Activity_Main.xml
<RelativeLayout 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=".MainActivity"
android:background="@drawable/background"
>
<TextView
android:id="@+id/headText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_3d_objects"
android:textSize="30sp"
android:layout_margin="12dp"
android:textStyle="bold"
android:textColor="@color/black"
/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:columnCount="3"
android:background="@drawable/gridback">
<androidx.cardview.widget.CardView
android:id="@+id/cardCube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="0"
android:layout_column="0"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/cube_shiv"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/cube"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardBee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="0"
android:layout_column="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/bee_shiv_foreground"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/bee"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="1"
android:layout_column="0"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_add_24"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/add"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
我还在 Gradle 依赖中添加了 CardView 和 GridLayout 库,但我的问题没有解决。
我能做什么?
这是我的 Gradle 文件
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
卡片视图的任何替代方案?
我该如何解决我的问题
我已经复制了你的代码并且运行它在我的 IDE,
首先,在这一行
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
我不知道您使用的 kotlin_version
,但我已经删除了这一行并且它对我来说成功了。但在您的情况下,请确保您使用的是正确的库,或者如果您在其他任何地方都不需要它,请删除此行。
其次,我已经删除了您使用的所有图像,因为我没有它们,因此请确保问题与图像无关。
第三,我使用了本地字符串而不是你的字符串,因为我在字符串文件中没有你的字符串,所以确保问题不相关到字符串。
当前应用截图:
我正在 GridLayout 中制作卡片视图。我 运行 我的应用程序在我的真实设备上。我的 CardView 不显示 我也在 Whosebug 中检查了这个问题,但这个问题可能与我的代码不同
这是我的Activity_Main.xml
<RelativeLayout 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=".MainActivity"
android:background="@drawable/background"
>
<TextView
android:id="@+id/headText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_3d_objects"
android:textSize="30sp"
android:layout_margin="12dp"
android:textStyle="bold"
android:textColor="@color/black"
/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:columnCount="3"
android:background="@drawable/gridback">
<androidx.cardview.widget.CardView
android:id="@+id/cardCube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="0"
android:layout_column="0"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/cube_shiv"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/cube"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardBee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="0"
android:layout_column="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/bee_shiv_foreground"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/bee"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row="1"
android:layout_column="0"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_add_24"
android:contentDescription="@string/todo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:text="@string/add"
android:textColor="@color/black" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
我还在 Gradle 依赖中添加了 CardView 和 GridLayout 库,但我的问题没有解决。 我能做什么?
这是我的 Gradle 文件
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
卡片视图的任何替代方案? 我该如何解决我的问题
我已经复制了你的代码并且运行它在我的 IDE,
首先,在这一行
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
我不知道您使用的 kotlin_version
,但我已经删除了这一行并且它对我来说成功了。但在您的情况下,请确保您使用的是正确的库,或者如果您在其他任何地方都不需要它,请删除此行。
其次,我已经删除了您使用的所有图像,因为我没有它们,因此请确保问题与图像无关。
第三,我使用了本地字符串而不是你的字符串,因为我在字符串文件中没有你的字符串,所以确保问题不相关到字符串。
当前应用截图: