Я использую RecyclerView, который отображает CardView. Этот CardView имеет 2 TextView и один GridView . GridView отображает CardView (давайте назовем его inside_card ) своим дочерним элементом. Теперь я не могу изменить высоту этой внутренней_карты. Ниже приведено то, чего я хочу достичь (изображение A) и то, что я получаю (изображение B).
Ниже приведены мои макеты. activity_main.xml содержит RecylerView
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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:orientation="vertical"
tools:context=".Activities.MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.appcompat.widget.LinearLayoutCompat>
activity_card.xml Содержит макет для отображения внутри RecyclerView.
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#AAA"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
android:layout_margin="8dp"
android:requiresFadingEdge="vertical">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/proffName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ProfessorName"
android:textAlignment="center"
android:gravity="center_horizontal">
</TextView>
<TextView
android:id="@+id/subjectCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SemesterName"
android:textAlignment="center"
android:gravity="center_horizontal">
</TextView>
<GridView
android:layout_gravity="center"
android:id="@+id/unitsGrid"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:layout_margin="6dp"
android:horizontalSpacing="2dp"
android:numColumns="2"></GridView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>
inside_card.xml содержит макет, отображаемый внутри GridView.
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inside_card"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="8dp"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
app:cardBackgroundColor="#eeeeee"
>
<TextView
android:textAlignment="center"
android:layout_gravity="center"
android:id="@+id/unitName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
</androidx.cardview.widget.CardView> ```
1 ответ
Изменение в файле inside_card.xml
-> Увеличьте высоту просмотра карты с 45dp до 120dp, настройте в соответствии с требованиями
-> Установить высоту карты 0dp, как и в дизайне А высоты карты нет.
-> Даже я предложу, не используйте для этого карточный вид, просто возьмите простой LienarLayout и установите для этого рисуемую форму с обводкой. Потому что установка границы в карточке - немного утомительная задача.
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inside_card"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="8dp"
app:cardCornerRadius="6dp"
app:cardElevation="0dp"
app:cardBackgroundColor="#eeeeee"
>
<TextView
android:textAlignment="center"
android:layout_gravity="center"
android:id="@+id/unitName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
</androidx.cardview.widget.CardView> `
В вашем GridView также установите интервал по вертикали
<GridView
android:layout_gravity="center"
android:id="@+id/unitsGrid"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:layout_margin="6dp"
android:horizontalSpacing="15dp"
android:verticalSpacing="15dp"
android:numColumns="2"></GridView>
Похожие вопросы
Новые вопросы
java
Java — это высокоуровневый объектно-ориентированный язык программирования. Используйте этот тег, если у вас возникли проблемы с использованием или пониманием самого языка. Этот тег часто используется вместе с другими тегами для библиотек и/или фреймворков, используемых разработчиками Java.