2012-03-01 9 views
5

私はCustomComponentViewGroupを拡張するクラスを持っています。 CustomComponentスクロールバーからカスタムViewGroup

ソースコード:

 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

こんにちはナタリ、私はこの質問が知っている余りに古いものですが、これを解決しましたか?もしあなたがそれを持っていれば、それはポストする。私は同様の状況で立ち往生しています – silwar

+0

こんにちは。私はそれに対して何も解決策が見つからなかったので、カスタムビュー(カラーボックス)を持つ相対レイアウトを子ビューとして使用しました。 – Natali

答えて

1

あなたはScrollViewの内側にあなたのMenuComponentを含めるように試みることができる:

<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

私はこの質問をする前にこれを試していますが、このxmlでは黒い画面があります。私のVEFグラウトは作成されましたが、残念ながらそれは表示されません。 – Natali

+0

あなたの問題についての詳細情報を追加できますか?カスタムMenuComponentで何を実現したいですか?あなたはどんなエラーを出していますか? –

+0

私のコンポーネントのスキームを追加しました。私はny 'ViewGroup'を' duration'サイズにスクロールダウンする必要があります。 – Natali

1

これを試してみてください。 ScrollView内にLinearLayoutが必要です。 MenuComponentを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

また、あなたが機能computeVerticalScrollExtent()とをオーバーライドする必要があります(more details)。カスタムのViewGroupに描画するスクロールバーをトリガする、awakenScrollBars()を呼び出す必要があり、有効になって垂直スクロールバーがsetVerticalScrollBarEnabled()

真である必要がありますcomputeVerticalScrollRange親指のサイズとスクロールバースクロール範囲を設定します。

関連する問題