我将在另一个布局下使用网格视图制作菜单。我使用recyclerview创建了gridview,但无法显示顶层布局我的代码是
活动\u grid\u layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".main.HomeActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dataList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
网格布局.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/layoutMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10sp"
android:layout_marginEnd="10sp"
android:layout_marginTop="20sp"
android:layout_marginBottom="5sp"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="8sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20sp"
android:paddingBottom="20sp"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="@+id/image_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home"/>
<TextView
android:id="@+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/news"
android:textSize="10sp"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
结果呢
请帮我解决这个问题,因为我是android开发者的初学者谢谢
1条答案
按热度按时间5w9g7ksd1#
不包括您的
LinearLayout
内部grid_layout.xml
把这个放进去activity_grid_layout.xml
就在recyclerview上面完成上述操作后,您的布局将发生以下变化:
活动\u grid\u layout.xml
网格布局.xml: