Моя цель: сделать какую-нибудь прокручиваемую галерею (для разнообразия).Я использую GridLayout с CardView.
Я прочитал много потоков и обнаружил, что мне нужно вставить ScrollView и поместить в него свой контент, который нужно прокрутить.Дело в том, почему мой прокручиваемый контент исчезает, когда я добавляю ScrollView вокруг?
Без ScrollView он отлично отображается (за исключением того, что, следовательно, все отображается на одной и той же "странице")и так, слишком маленький).
Не могли бы вы объяснить, почему это не работает?
Большое спасибо:)
Это мой код XML:
<LinearLayout
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"
tools:context=".RecipeActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:rowCount="3"
android:columnCount="2">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:clickable="true"
android:onClick="seeRecipe">
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/chocolatine"/>
<!-- random TextView -->
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- 15 more android.support.v7.widget.CardView -->
</GridLayout>
</ScrollView>
</LinearLayout>
Мой код Java пуст, за исключением необходимых вещей (onCreate ...).