Reputation: 505
i am trying to show one gridview while selecting some photo from gallery and showing list with recyclerview in a fragment. my layout working well if i do not use swipe refresh layout. can you solve this why this layout not working while using swipe refreshlayout.
xml:
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.systechdigital.webadeal.NewsfeedFragment"
android:orientation="vertical"
android:background="#969696"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#023956"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="50dp"
android:src="@drawable/globe"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:id="@+id/notificationButtonId"
android:background="?android:attr/selectableItemBackground"
android:paddingRight="10dp"
/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Share you thoughts here..."
android:paddingLeft="10dp"
android:background="@drawable/edittext_status_background"
android:padding="20dp"
android:elevation="5dp"
android:id="@+id/editTextWritePostId"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fitsSystemWindows="true"
android:background="#f9f9f9"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post"
android:textColor="#ffffff"
android:background="#1470a6"
android:id="@+id/postButtonId"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkInButtonId"
android:layout_toLeftOf="@+id/smileyButtonId"
android:layout_centerInParent="true"
android:src="@drawable/ic_checkin"
android:background="@android:color/transparent"
android:layout_marginRight="3dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/smiley"
android:layout_toLeftOf="@+id/imageUploadButtonId"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:id="@+id/smileyButtonId"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/camera"
android:layout_toLeftOf="@+id/videoUploadButtonId"
android:layout_centerInParent="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:id="@+id/imageUploadButtonId"
/>
</RelativeLayout>
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gridViewId"
android:layout_below="@+id/postButtonId"
android:numColumns="auto_fit"
android:columnWidth="100dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/underline"
android:minHeight="0dp"
/>
**<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/swipeRefreshLayoutId"
>**
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerviewId_newsFeed"
android:nestedScrollingEnabled="true"
/>
**</android.support.v4.widget.SwipeRefreshLayout>**
</LinearLayout>
</ScrollView>
</LinearLayout>
Upvotes: 0
Views: 3918
Reputation: 21736
1. Don't use GridView
, ListView
or RecyclerView
inside ScrollView
. Use NestedScrollView
instead of your ScrollView
.
NestedScrollView
is just likeScrollView
, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.
2. Use SwipeRefreshLayout
as parent of NestedScrollView
.
3. Use attribute android:descendantFocusability="blocksDescendants"
to LinearLayout
instead of android:descendantFocusability="beforeDescendants"
.
4. Use attribute android:nestedScrollingEnabled="false"
to RecyclerView
.
Update your layout as below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#969696">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#023956">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="50dp"
android:src="@drawable/ic_group"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:id="@+id/notificationButtonId"
android:background="?android:attr/selectableItemBackground"
android:paddingRight="10dp" />
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipeRefreshLayoutId">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:descendantFocusability="blocksDescendants">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Share you thoughts here..."
android:paddingLeft="10dp"
android:padding="20dp"
android:elevation="5dp"
android:id="@+id/editTextWritePostId" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fitsSystemWindows="true"
android:background="#f9f9f9">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post"
android:textColor="#ffffff"
android:background="#1470a6"
android:id="@+id/postButtonId" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkInButtonId"
android:layout_toLeftOf="@+id/smileyButtonId"
android:layout_centerInParent="true"
android:src="@drawable/ic_action_cart"
android:background="@android:color/transparent"
android:layout_marginRight="3dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_play"
android:layout_toLeftOf="@+id/imageUploadButtonId"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:id="@+id/smileyButtonId" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_camera"
android:layout_centerInParent="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:id="@+id/imageUploadButtonId" />
</RelativeLayout>
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gridViewId"
android:layout_below="@+id/postButtonId"
android:numColumns="auto_fit"
android:columnWidth="100dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerviewId_newsFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Hope this will help~
Upvotes: 1
Reputation: 69671
just replace your swipe view at top of your layout like this
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayoutId"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#969696"
android:orientation="vertical"
tools:context="com.systechdigital.webadeal.NewsfeedFragment"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#023956">
<ImageButton
android:id="@+id/notificationButtonId"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="?android:attr/selectableItemBackground"
android:paddingRight="10dp"
android:src="@drawable/globe" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="10dp">
<EditText
android:id="@+id/editTextWritePostId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_status_background"
android:elevation="5dp"
android:hint="Share you thoughts here..."
android:padding="20dp"
android:paddingLeft="10dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#f9f9f9"
android:fitsSystemWindows="true">
<Button
android:id="@+id/postButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1470a6"
android:text="Post"
android:textColor="#ffffff" />
<ImageButton
android:id="@+id/checkInButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="3dp"
android:layout_toLeftOf="@+id/smileyButtonId"
android:background="@android:color/transparent"
android:src="@drawable/ic_checkin" />
<ImageButton
android:id="@+id/smileyButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/imageUploadButtonId"
android:background="@drawable/smiley" />
<ImageButton
android:id="@+id/imageUploadButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/videoUploadButtonId"
android:background="@drawable/camera" />
</RelativeLayout>
<GridView
android:id="@+id/gridViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/postButtonId"
android:layout_marginTop="5dp"
android:columnWidth="100dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/underline"
android:minHeight="0dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerviewId_newsFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Upvotes: 0