У меня есть проблема, которая, кажется, влияет только на версии Android 4.x и может быть также специфичной для устройства (т. Е. Она не существует на моем Huawei [email protected], но существует на Samsung [email protected]). У меня есть ScrollView
, который содержит RelativeLayout
, который имеет 4 CardView
s. Теперь на некоторых устройствах 4.x событие прокрутки просто не происходит, когда я пытаюсь прокручивать начало с карты. Если я коснусь маленькой прокладки между картами или выше первой карты (а не между любыми двумя) и экраном устройства, я могу прокручивать содержимое.ScrollView внутри ViewPager не прокручивается на Android 4.x
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
<android.support.v7.widget.CardView
android:id="@+id/metricsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="@drawable/metrics"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/metrics"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/warningsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@id/metricsContainerCard"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="@drawable/bug_color"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/warnings"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/topWarningsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/warningsContainerCard"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="@drawable/top_warnings"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/topWarnings"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/topCriticalItemsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/topWarningsContainerCard"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="@drawable/top_critical_items"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/topCriticalItems"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
Нет проблем на Android 5.x и 6.x.
EDIT
кажется, что проблема не связана исключительно с CardView
, поскольку у меня есть еще один макет, и он также не прокручивается даже тогда, когда я перетащить на экран с помощью настраиваемого представления:
<ScrollView
android:id="@+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".projects.details.ProjectDetailsActivity_">
<LinearLayout 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"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/projectName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:ellipsize="none"
android:gravity="center_horizontal"
android:text="Project name"
android:textSize="24sp"/>
<c.f.q.a.projects.details.components.widgets.ProjectDetailWidget
android:id="@+id/projectDetailWidget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:id="@+id/timelineWrapperLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/qualityTimelineCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/flipQualityTimelineButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="@drawable/flip_to_cost"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:lines="1"
android:text="@string/project_timeline_title"
android:textSize="16dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/projectQualityTimelineProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/projectQualityTimeline"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/costTimelineCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="gone"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/flipCostTimelineButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="@drawable/flip_to_quality"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:lines="1"
android:text="@string/project_cost_timeline_title"
android:textSize="16dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/projectCostTimelineProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/projectCostTimeline"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
android:id="@+id/vcsChangeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/expandVcsChangeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="@drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/project_vcschange_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/vcsChangeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/projectVcsChange"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/dtnosChangeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/expandDtnosChangeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="@drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/project_systemchange_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/dtnosChangeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/projectDtnosChange"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/sensorNodeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/expandSensornodeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="@drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/project_sensornode_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/sensorNodeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.RadarChart
android:id="@+id/sensorNodeChart"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/aggregateNodeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/expandAggregateButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="@drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/project_aggregatenode_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/aggregateNodeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.RadarChart
android:id="@+id/aggregateNodeChart"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="@string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
я добавил полный макет, а также здесь изображение для осветления (я обозначил прокрутку области, которые я могу перетащить):
EDIT2
Может быть, это также важно, чтобы эти макеты фрагментов внутри ViewPager
. Возможно ли, что ViewPager
предотвращает ScrollView
(и любые другие виды внутри него), получая фокусировку/обработку событий касания? Код для моего ViewPager
это:
<android.support.v4.view.ViewPager
android:id="@+id/projectPager"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
EDIT3
Кажется, что проблема должна быть с ViewPager
+ (Nested)ScrollView
(я пытался обменять обычную ScrollView
с этим, но безуспешно). Я создал фиктивный макет для моего фрагмента, который только хозяйничает родитель NestedScrollView
, а LinearLayout
и многая крупной TextView
ей это нравится:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="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=".projects.details.ProjectDetailsActivity_">
<LinearLayout 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"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:ellipsize="none"
android:gravity="center_horizontal"
android:text="Project name"
android:textSize="80sp"/>
... <!-- more TextViews come here -->
... и прокрутка тоже не работает! Только на самом краю экрана, как и раньше. Я понятия не имею, как это может случиться ...
От вашего редактирования кажется, что это не связано с CardView - возможно, вы могли бы переиздать, чтобы опустить CardView, и предоставить вместо этого дополнительную информацию о остальной части вашей установки. – ataulm
Вы пытались установить 'android: clickable =" true "и' android: focusable = "true" 'атрибуты' CardView'? – fillobotto
Да, я попробовал их, не повезло. Я редактировал свой пост с более подробной информацией, может быть, это может помочь. – Sleeper9