2016-02-25 21 views
5

के अंदर एक सूची दृश्य कैसे हो सकता है मैंने एक ऐसे पृष्ठ के साथ एक ऐप बनाया है जिसे वेब सेवा से गतिशील रूप से सामग्री लोड करने की आवश्यकता है। मैं सूचीदृश्य देखना चाहता हूं जो NestedScrollView के अंदर एक रैखिक लेआउट के साथ स्क्रॉल कर सकता है। लेकिन जब सामग्रियों को सूचीदृश्य में लोड किया जाता है, तो यह इसकी पूर्ण ऊंचाई तक खरोंच नहीं करता है।मेरे पास NestedScrollView

मेरा कोड यहां है।

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.myquestionth.myquestionth10.Profile2Activity" 
    tools:showIn="@layout/activity_profile2"> 

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

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

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="400dp" 
       android:background="#BBBBBB" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Media heading" 
       android:id="@+id/textView2" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis." 
       android:id="@+id/textView8" /> 

     </LinearLayout> 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#70bcf5" /> 

    </LinearLayout> 

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

मैंने स्क्रॉलव्यू के बारे में कुछ खोज की है, जिसे नेस्टेड नहीं किया जा सकता है। यह एक उदाहरण है जिसे मैं Google Play समीक्षा पृष्ठ से अपने लेआउट डिज़ाइनिंग के अनुसार चाहता हूं। वे किस विधि का उपयोग करते हैं? अगर मैं कुछ गलत करता हूं तो मुझे सुझाव दें। बहुत धन्यवाद।

enter image description here

यहाँ मैं क्या चाहते है।

enter image description here

+1

सूचीदृश्य की ऊंचाई को ठीक करें। या सबसे अच्छा तरीका समन्वयक और रीसाइक्लिंग व्यू का उपयोग करना है। [यह] देखें (http://inthecheesefactory.com/blog/android-design-support-library-codelab/en) –

उत्तर

4

ठीक है, मैं आपको लगता है कि समस्या को हल करने के 2 तरीके सुझाव है। ध्यान दें कि हेडर को फुलाया जाना चाहिए क्योंकि यह here लिखा गया है।

2) आपने कहा है कि आप NestedScrollView उपयोग करते हैं, तो हो सकता है आप भी LinearLayout के साथ अंदर नेस्टेड scrollview ListView को बदलने के लिए प्रयास करना चाहिए, के रूप में बुद्धिमान लोग here का सुझाव दिया, कैसे अपने अनुकूलक काम करता है के लिए इसी तरह पाश में पंक्ति विचारों को जोड़ने।

शुभकामनाएं!

1

के बजाय एक रेखीय लेआउट नीचे और एक scrollview के अंदर एक ListView जोड़ने के लिए, मैं ListView अंदर सब कुछ डाल करने के लिए सुझाव है।

हाँ आप कर सकते हैं।

लागू (ओवरराइड) अपने एडाप्टर पर निम्न विधि:

public class MyAdapter extends BaseAdapter { 
    // One view to Header 
    // One view to filter options ("most helpful first" and "Options") 
    // One view to comments 
    private final static int VIEW_HEADER = 0; 
    private final static int VIEW_OPTIONS = 1; 
    private final static int VIEW_COMMENTS = 2; 
    private final static int VIEW_TYPE_MAX = 3; 

    @Override 
    public int getViewTypeCount() { 
     // It will return 3 since I have 3 different types of VIEW 
     return VIEW_TYPE_MAX; 
    } 

    @Override 
    public int getItemViewType(int position) { 
     if (position == 0) 
      return VIEW_HEADER; 
     else if (position == 1) 
      return VIEW_OPTIONS; 
     else 
      return VIEW_COMMENTS; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      if(getItemViewType(position) == VIEW_HEADER) 
       // Inflate HEADER Layout 
      else if (getItemViewType(position) == VIEW_OPTIONS) 
       // Inflate Options Layout 
      else 
       // Inflate comments Layout 
     } 

     // Fill the view contents according to its type 
     .... 
     return convertView; 
    } 
} 

एंड्रॉयड विचारों को फिर से प्रयोग करेंगे। हालांकि एंड्रॉइड हमेशा एक ही प्रकार के विचारों का पुन: उपयोग करेगा।

1) अपने ListView का एक हैडर LinearLayout बनाने की कोशिश करें:

+0

धन्यवाद Guiherme मैं कोशिश करूँगा। – Marcus

+0

आपका स्वागत है .. एलेक्स मिर्च के उत्तर का भी प्रयास करें ... यह मूल उत्तर देने के लिए आसान – W0rmH0le

3

लॉलीपॉप पर बाद आप उपयोग कर सकते

yourtListView.setNestedScrollingEnabled(true); 

यह सक्षम या इस दृश्य को के लिए नेस्टेड स्क्रॉल को निष्क्रिय करता है, तो आप पीछे की ओर ओएस आप RecyclerView का उपयोग करना होगा के पुराने संस्करण के साथ संगतता की जरूरत है।

+0

[क्रेडिट] (https://stackoverflow.com/a/35198484/4015799) लगता है। –

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