2011-07-22 9 views
1

これはカスタマイズ可能なオーバースキャンでListViewを作成する作業です。RelativeLayoutを拡張する

私は、RelativeLayoutを拡張するカスタム要素を作成したいが、子ビューを追加することはうまくいっていない。コードは正しいようだが、ビューはやや狂ったように見える。

underscrollEdge = new ImageView(context); 
    underscrollEdge.setImageResource(R.drawable.underscroll_edge); 
    underscrollGlow = new ImageView(context); 
    underscrollGlow.setImageResource(R.drawable.underscroll_glow); 
    overscrollGlow = new ImageView(context); 
    overscrollGlow.setImageResource(R.drawable.overscroll_glow); 
    overscrollEdge = new ImageView(context); 
    overscrollEdge.setImageResource(R.drawable.overscroll_edge); 

    RelativeLayout.LayoutParams topLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    topLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
    addView(underscrollEdge, topLayout); 
    addView(underscrollGlow, topLayout);   

    RelativeLayout.LayoutParams bottomLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    bottomLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    addView(overscrollGlow, bottomLayout);  
    addView(overscrollEdge, bottomLayout); 

これは、妙に、この(私はエッジを表示するために黒に相対レイアウトを設定し、点灯しました)を与える:あなたが見ることができるように

を、上端が浮いています真ん中のどこかに、そして底の輝きは、小さな小さなサイズにまで収縮しています。

答えて

0

問題を書き留めることは、私はそれを解決するのに役立ちますどのように愛:

RelativeLayout.LayoutParams topLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    topLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
    addView(underscrollGlow, topLayout);   
    topLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    topLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
    addView(underscrollEdge, topLayout);  

    RelativeLayout.LayoutParams bottomLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    bottomLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    addView(overscrollGlow, bottomLayout);  
    bottomLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    bottomLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    addView(overscrollEdge, bottomLayout); 

二つの成分に同じLayoutParamsの使用の物事が奇妙行かせます。面倒ですが、それは物事を修正します。