2012-03-01 17 views
5

पर स्क्रॉल बार मेरे पास CustomComponent कक्षा है जो ViewGroup फैली हुई है।कस्टम व्यू ग्रुप

CustomComponent की

स्रोत कोड:

 public class CustomComponent extends ViewGroup { 

      private static final String LOGTAG = "CustomComponent"; 

      private List<MenuItem> items; 

      private Context context; 

      private int screenWidth; 
      private int screenHeight; 
      private int cellWidth; 
      private int cellHeight; 
      private int duration; 
     private int space=7; 

     public CustomComponent(Context context) { 
      super(context); 
      this.context=context; 
     } 


      @Override 
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      Log.v(LOGTAG, "on Measure called"); 
      screenWidth = MeasureSpec.getSize(widthMeasureSpec); 
       screenHeight = MeasureSpec.getSize(heightMeasureSpec); 
       cellHeight=screenHeight/AppConstants.HEIDHTCELLSCOUNT; 
       cellWidth=screenWidth/AppConstants.WIDTHCELLSCOUNT; 
       duration= cellHeight*2; 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec+duration); 

      } 


      @Override 
     protected void onLayout(boolean changed, int l, int t, int r, int b) { 
      Log.v(LOGTAG, "onLayout called"); 
      int childCount = this.getChildCount(); 
       for (int i = 0; i < childCount; i++) { 
         View child = getChildAt(i); 
          child.layout(items.get(i).getLeft(),items.get(i).getTop(),items.get(i).getRight(), items.get(i).getBottom()); 
     } 
     } 

public List<MenuItem> getItems() { 
     return items; 
    } 

    public void setItems(List<MenuItem> items) { 
     this.items = items; 
    } 
    } 

XML लेआउट:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/menu_layout" 
    android:scrollbars="vertical"> 
     <<package name>.CustomComponentandroid:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:id="@+id/menu_component" 
      android:scrollbars="vertical" 
      android:fadingEdge="vertical"/> 
</LinearLayout> 

मैं इस ViewGroup को लंबवत स्क्रॉल जोड़ने की जरूरत है। कृपया मदद करें, मुझे नहीं पता कि इस समस्या को कैसे हल किया जाए। enter image description here

+0

[यहां] से कोड (http://code.google.com/p/android-masonry/source/checkout) मेरे लिए काम किया आप सूट करने के लिए तुम्हारा – almuneef

+0

हाय Natali कुछ संपादन की आवश्यकता हो सकती, मुझे पता है इस सवाल है बहुत पुराना लेकिन क्या आपको इसका समाधान मिला। यदि आपको यह मिल गया है तो इसे पोस्ट करें। मैं इसी तरह की स्थिति में फंस गया हूं – silwar

+0

हैलो। मुझे इसके लिए कोई समाधान नहीं मिला, इसलिए मैंने कस्टम दृश्यों (रंगीन बक्से) के साथ सापेक्ष लेआउट का उपयोग बच्चे के विचारों के रूप में किया। – Natali

उत्तर

1

आप अपने MenuComponent एक ScrollView अंदर शामिल करने के लिए कोशिश कर सकते:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/menu_layout" 
    android:scrollbars="vertical"> 
     <ScrollView android:id="@+id/ScrollView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <<package name>.MenuComponent android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:id="@+id/menu_component" 
      android:scrollbars="vertical" 
      android:fadingEdge="vertical"/> 
     </ScrollView> 
</LinearLayout> 
+0

मैं इस सवाल से पहले यह कोशिश करता हूं, लेकिन इस एक्सएमएल के साथ मेरी ब्लैक स्क्रीन है। मेरा viev grout बनाया गया है लेकिन दुर्भाग्य से यह दिखाया नहीं गया है। – Natali

+0

क्या आप अपनी समस्या के बारे में अधिक जानकारी जोड़ सकते हैं? आप अपने कस्टम मेनू कॉम्पोनेंट के साथ क्या हासिल करना चाहते हैं? आपको क्या त्रुटियां मिल रही हैं? –

+0

मैंने अपने घटक की योजना को जोड़ा। मुझे 'अवधि समूह' में 'अवधि' आकार में स्क्रॉल डाउन जोड़ने की आवश्यकता है। – Natali

1

इस प्रयास करें। आपको ScrollView के अंदर एक लीनियरआउट की आवश्यकता है। LinearLayout के अंदर अपना मेनू कॉम्पोनेंट रखें। यह काम करना चाहिए।

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/menu_layout" 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <<package name>.MenuComponent android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:id="@+id/menu_component" 
       android:scrollbars="vertical" 
       android:fadingEdge="vertical"/> 
     </LinearLayout> 

    </ScrollView> 
</LinearLayout> 
+0

दुर्भाग्यवश मेरे पास एक ही 'बैलक स्क्रीन' है। :( – Natali

+0

क्या आपने समस्या को हल करने का प्रबंधन किया था? – Shubhayu

+0

नहीं, मुझे नहीं पता कि यह कैसे करें। – Natali

0

आप awakenScrollBars() कॉल करने के लिए है, जो अपने कस्टम viewGroup पर आकर्षित करने के लिए स्क्रॉलबार ट्रिगर किया जाएगा है। (more details) और ऊर्ध्वाधर स्क्रॉलबार सक्षम सच setVerticalScrollBarEnabled()

इसके अलावा, आप कार्यों को ओवरराइड करने के लिए है हो गया है computeVerticalScrollExtent() और अंगूठे के आकार और स्क्रॉलबार स्क्रॉल रेंज सेट करने के लिए computeVerticalScrollRange

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

  • कोई संबंधित समस्या नहीं^_^