2015-07-11 11 views
7

मैं कई CardView के रूप में एक्सएमएल में परिभाषित:परिवर्तनीय ऊंचाई के साथ कार्डव्यू का ग्रिड लेआउट कैसे बनाएं?

<android.support.v7.widget.CardView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    card_view:cardPreventCornerOverlap="false" 
    card_view:cardCornerRadius="4dp"> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:textSize="@dimen/abc_text_size_title_material" 
      android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

फोन के लिए, मैं लिपटे है कई CardView 'है रों एक ऊर्ध्वाधर LinearLayout में:

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

टेबलेट के लिए, मैं चाहते हैं Material Design specs में उपयोग किए गए डिज़ाइन के समान, इसके बजाय ग्रिड लेआउट का उपयोग करें, छवि here देखें।

ग्रिड लेआउट बनाने के लिए उपयोग करने के लिए सबसे अच्छा ViewGroup क्या है? कार्ड परिवर्तनीय ऊंचाई के हैं, और स्थिर सामग्री है।

GridLayout का उपयोग नहीं किया जा सकता है, क्योंकि कार्ड परिवर्तनीय ऊंचाई के हैं।

उत्तर

12

मुझे कुछ समय पहले इसी समस्या का सामना करना पड़ा था। हां, आप GridLayout का उपयोग नहीं कर सकते क्योंकि आपके कार्ड परिवर्तनीय आकार के हैं। तो आप StaggeredGridView के लिए क्या देख रहे हैं जो इसकी वस्तुओं को परिवर्तनीय आकारों की अनुमति देता है। आप उपयोग कर सकते this या this पुस्तकालय

1) -:

आप निम्नलिखित के दोनों कर सकते हैं। वे उपयोग करने के लिए बहुत आसान हैं। मैंने दोनों का उपयोग किया है और मैं आपको आश्वस्त कर सकता हूं कि वे अपना काम पूरी तरह से करते हैं।

2) आप Google से RecyclerView.StaggeredGridLayoutManager को आजमा सकते हैं।

एक नमूना कोड इस तरह somethings विचार करेंगे,

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); 
    recyclerView.setAdapter(adapter); 

आशा है कि यह आप में मदद करता है।

+0

दूसरा विकल्प सबसे अच्छा मुझे लगता है .. – Hardy

1

टैबलेट के लिए आप 2 LinearLayouts का उपयोग कर सकते हैं।

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