2015-10-11 20 views
12

Dinamik içeriği görüntüleyen bir RecyclerView var. Bu RecyclerView görünümünü diğer Görünümler arasında görüntüleyeceğim. Ben çalışıyor gibi görünmüyor denemek ve RecyclerView tüm yer kaplar gibi görünüyor olursa olsun, AncakYukarıdaki ve yukarıdaki görünümler RecyclerView

View 
RecyclerView 
View 

: Örneğin, bir Görünüm ve üstünde RecyclerView altında görüntülenen bir Görünüm sergiledi. Sorunun, this custom LinearLayoutManager gibi bazı önerilen çözümleri denedim, ancak sorunumu gidermek için görünmüyor olsa da, sorunun wrap_content issue içinde bulunduğuna inanıyorum.

Denemesi:

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

Soru: yukarıda Görünüm ve RecyclerView altında bir görünümü yerleştirmek ve görüntülemek için bir yolu var mı? Öyleyse nasıl? Yoksa bir ListView kullanmak daha mı iyi?

cevap

25

Ne weight kullanımıyla ilgili?

Recyclerview Adaptörü içinde
<?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

Düzenim, verdiğim örnekte olduğundan veya RecyclerView ile bilinen hatadan biraz daha karmaşık olduğundan, yalnızca bir layout_weight eklenmesi işe yaramadı. Ancak, bir RecyclerView yerine bir ListView kullanmaya karar verdim ve ListView'e layout_weight ekleyerek istediğim etkiyi verdim. – chRyNaN

+1

Harika cevap. Bu benim için iyi çalıştı. – Mythul

+0

Mükemmel Süper Harika ...... –

1

Bu sizin tipik çözümünüz olmayabilir, ancak yine de deneyebilirsiniz.

LinearLayout yerine RelativeLayout kullanımı ve SwipeRefreshLayout öğesinin üst ve alt dolgularını aşağıdaki şekilde görünümlerinizin yüksekliğine ayarlamaya ne dersiniz?

<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

Üst ve alt görünümlerimin boyutu dinamik olarak değiştiği için bu benim için geçerli bir çözüm değil. – chRyNaN

+0

Neden dolguyu dinamik olarak sıfırlamıyorsunuz? – Ari

+0

Dolgu ile mesajlaşma dinamik olarak benim için çalışmadı. Bunun yerine bir ListView kullanarak sonuçlandı ve istenen efektimi üreten layout_weight özniteliğini ekledim. Yardım ettiğin için teşekkür ederim. – chRyNaN

İlgili konular