2017-06-19 51 views
0

我试图同时选择从画廊的一些照片,并显示在一个片段recyclerview列表显示一个GridView的刷新。我的布局运行良好,如果我不使用刷卡刷新布局。你能解决这个为什么这个布局不工作,而使用刷卡refreshlayout。拉在滚动视图的Android

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> 
+0

看到这个【答案】(https://stackoverflow.com/a/36337019/7134908),这将绝对帮助你。 –

+0

无法正常工作。,,。, – AAA

+0

使用NestedScrollView而不是滚动型。 –

回答

0

只需更换您的刷卡视图在布局的顶部像这样

<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> 
+0

不工作,我想 – AAA

+0

的方式??? –

+0

意味着它不工作,我想当我滚动一切将向上/向下滚动但不工作 – AAA

0

不要使用GridViewListViewRecyclerViewScrollView。使用NestedScrollView而不是您的ScrollView

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

2.使用SwipeRefreshLayout作为NestedScrollView父。

使用属性android:descendantFocusability="blocksDescendants"LinearLayout而不是android:descendantFocusability="beforeDescendants"

4.使用属性android:nestedScrollingEnabled="false"RecyclerView。如下

更新您的布局:

<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> 

希望这将有助于〜

+0

不工作:(。,。, – AAA

+0

应用我的更改后,目前的状态是什么? – FAT

+0

相同输出如前 – AAA