1

我有一個RecyclerView作爲SwipeRefreshLayout的唯一孩子,我想要RecyclerView wrap_content。當我將它們都設置爲「wrap_content」時,它不起作用。 RecyclerView與更少的項目也match_parent。當我刪除SwipeRefreshLayout時,RecyclerViewwrap_content。誰能幫我?我的英語很差,也許你不能理解。任何人都可以幫助我?非常感謝你。SwipeRefreshLayout中的RecyclerView不是「wrap_content」

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container_v" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#00ffff"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ff00ff"> 


    </android.support.v7.widget.RecyclerView> 
</android.support.v4.widget.SwipeRefreshLayout> 

+0

後的XML代碼plz.and嘗試WRAP_CONTENT爲SwipeRefreshLayout太 –

+0

我已經設置了'SwipeRefreshLayout'到'wrap_content',但'RecyclerView'也是'match_parent' –

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container_v" 
    android:layout_width="match_parent" 
    android:weightSum="1" 
    android:orientation="vertical" 
    android:layout_height="match_parent" 
    tools:context=".classes.Splash"> 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight=".5" 
     android:background="#00ffff"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#ff00ff"> 


     </android.support.v7.widget.RecyclerView> 
    </android.support.v4.widget.SwipeRefreshLayout> 

你可以嘗試給權重線性layout.It將工作

2

最後,我工作了它。從this Answer

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container_v" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#00ffff"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#ff00ff" /> 


    </LinearLayout> 


</android.support.v4.widget.SwipeRefreshLayout>