2015-10-11 12 views
12

मेरे पास एक रीसाइक्लिंग व्यू है जो गतिशील सामग्री प्रदर्शित करता है। मैं इस रीसाइक्लिंग व्यू को अन्य दृश्यों के बीच प्रदर्शित करना चाहता हूं। उदाहरण के लिए, एक दृश्य के ऊपर और एक दृश्य RecyclerView नीचे प्रदर्शित दिखाया गया है:ऊपर और नीचे रीसाइक्लर व्यू

View 
RecyclerView 
View 

हालांकि, जो कुछ भी मैं कोशिश काम नहीं लगता है और RecyclerView पूरे स्थान ले रहा है। मेरा मानना ​​है कि समस्या wrap_content issue में निहित है, हालांकि मैंने कुछ सुझाए गए समाधानों की कोशिश की है, जैसे this custom LinearLayoutManager, फिर भी यह मेरी समस्या को ठीक नहीं कर रहा है।

प्रयास:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

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

     <!-- AppBar works fine; no issue here --> 
     <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:id="@+id/app_bar_layout"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_width="match_parent" 
       app:layout_collapseMode="pin"/> 

     </android.support.design.widget.AppBarLayout> 

     <!-- Not displaying; Tried different views --> 
     <com.chrynan.taginput.view.TextInputWrapper 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/edit_text_container"> 
      <AutoCompleteTextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/edit_text"/> 
     </com.chrynan.taginput.view.TextInputWrapper> 

     <!-- Takes up entire screen space --> 
     <android.support.v4.widget.SwipeRefreshLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/swipe_refresh"> 

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

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

     <!-- Not displaying --> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/text_view"/> 

    </LinearLayout> 

</android.support.design.widget.CoordinatorLayout> 

प्रश्न: वहाँ जगह है और इसके बाद के संस्करण एक दृश्य और एक RecyclerView के नीचे एक दृश्य प्रदर्शित करने के लिए कोई तरीका है? यदि हां, तो कैसे? या ListView का उपयोग करना बेहतर है?

उत्तर

25

क्या weight के उपयोग के बारे में?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://..." 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"   
    android:orientation="vertical" 
    > 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

    <RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 
+0

या तो क्योंकि मेरे लेआउट उदाहरण मैं दे दी है की तुलना में या RecyclerView साथ ज्ञात बग की वजह से थोड़ा अधिक जटिल है, बस एक layout_weight जोड़ने काम नहीं किया। हालांकि, मैं एक RecyclerView के बजाय एक ListView उपयोग करने का फैसला, और ListView को layout_weight जोड़ने मुझे वांछित प्रभाव देना था। – chRyNaN

+1

ग्रेट उत्तर। यह मेरे लिए ठीक काम किया। – Mythul

+0

उत्कृष्ट सुपर बहुत बढ़िया ...... –

1

यह आपका सामान्य समाधान नहीं हो सकता है, लेकिन फिर भी आप इसे आजमा सकते हैं।

लीनियरलाउट के बजाय रिलेवेटिवआउट का उपयोग करने के बारे में, और अपने विचारों की ऊंचाई पर अपने स्वाइप रीफ्रेशलेआउट के शीर्ष और नीचे पैडिंग को बस सेट करें।

<android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <!-- your app bar --> 

    <!-- Not displaying; Tried different views --> 
    <com.chrynan.taginput.view.TextInputWrapper 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:layout_alignParentTop="true" 
     android:id="@+id/edit_text_container"/> 

    <!-- Takes up entire screen space --> 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="150dp" 
     android:paddingBottom="250dp" 
     android:id="@+id/swipe_refresh"> 

     <android.support.v7.widget.RecyclerView 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/recycler_view"/> 

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

    <!-- bottom view --> 
    <TextView 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:id="@+id/text_view"/> 

</RelativeLayout> 

+1

दुर्भाग्य से यह मेरे लिए एक व्यवहार्य समाधान नहीं है मेरे ऊपर और नीचे देखा गया गतिशील आकार बदलने के बाद से। – chRyNaN

+0

पैडिंग को गतिशील रूप से रीसेट क्यों नहीं करें? – Ari

+0

गतिशील रूप से पैडिंग के साथ मेसिंग मेरे लिए काम नहीं किया। मैं बजाय एक ListView का उपयोग करने के परिणामस्वरूप और उस पर layout_weight विशेषता है, जो मेरी वांछित प्रभाव का उत्पादन गयी। आपकी सहायता के लिए धन्यवाद। – chRyNaN

1

उपयोग शीर्षक और RecyclerView के लिए पाद लेख, उपयोग viewtype Recyclerview एडाप्टर में और शीर्ष लेख और पाद view.The समस्या आप का सामना कर रहे जोड़ने एक लेआउट में एक से अधिक scollview की वजह से है और सबसे अच्छा समाधान शीर्ष लेख और पाद का उपयोग करना है, यह इसे एकल स्क्रॉलव्यू के रूप में बना देगा। अधिक जानकारी के लिए इस लिंक को देख https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type?rq=1

संबंधित मुद्दे