2015-12-25 19 views
12

Her görünüm arasında yatay çizgilerle programa dayalı olarak program oluşturma yapıyorum. Programlı olarak oluşturulabilir bir çekmece kullanarak.Sürekli Saydamlık, sürekli donukluk istemek Resim Görünümü ile Çizilebilir

Sorun şu ki, opaklık ışıktan başlıyor ve her bir hat için kademeli olarak artar.

Çizilebilir, boya, görüntü görünümü ve doğrusal yerleşimin opaklığını (getAlpha()), sağlanan iki yöntemdeki tüm noktalarda ve her zaman 255 ve görünümleri 1.0 olan çekilebilir öğelerden kaydettim. Neden bu doğru değil sanki davranmıyor anlamıyorum. Alfa'yı da denedim, farketmez.

Bunu neden yapıyor ve nasıl düzeltebilirim?

xml:

<LinearLayout android:id="@+id/main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" .../> 

    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="PaintDashedLines" 
     android:text="Press Me"/> 
</LinearLayout> 

java: Bana göre

static int tvCount = 0; 

public void PaintDashedLines(View v) { 
    LinearLayout ll = (LinearLayout) findViewById(R.id.main); 
    TextView tv = new TextView(MainActivity.this); 
    tv.setGravity(Gravity.CENTER); 
    tv.setTextSize(25); 
    tv.setPadding(0, 5, 0, 5); 
    ll.addView(tv); 
    tv.setText("TextView " + tvCount); 
    ImageView divider = new ImageView(MainActivity.this); 
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
      ll.getWidth(), 2); 
    lp.setMargins(0, 5, 0, 5); 
    divider.setLayoutParams(lp); 
    divider.setBackground(CreateDashedLined()); 
    ll.addView(divider); 
    tvCount++; 
} 

public static Drawable CreateDashedLined() { 
    ShapeDrawable sd = new ShapeDrawable(new RectShape()); 
    Paint fgPaintSel = sd.getPaint(); 
    fgPaintSel.setColor(Color.BLACK); 
    fgPaintSel.setStyle(Paint.Style.STROKE); 
    fgPaintSel.setPathEffect(new DashPathEffect(new float[]{5, 10}, 0)); 
    return sd; 
} 

enter image description here

cevap

11

emülatörü ile daha bazı sorun gibi görünüyor. Ayrıca, sadece TextView s arasında bir ayırıcı çizmek, yeni ImageView her zaman örneğini gerekmez akılda da saklayın

ll.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

ile donanım hızlandırmasını devre dışı deneyebilirsiniz. SetDivider'ı kullanabilirsiniz. Örneğin. senin onCreate

ShapeDrawable sd = new ShapeDrawable(new RectShape()); 
sd.setIntrinsicHeight(1); 
Paint fgPaintSel = sd.getPaint(); 
fgPaintSel.setARGB(255, 0, 0, 0); 
fgPaintSel.setStyle(Paint.Style.STROKE); 
fgPaintSel.setPathEffect(new DashPathEffect(new float[]{5, 10}, 0)); 

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main); 
linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE | LinearLayout.SHOW_DIVIDER_END); 
linearLayout.setDividerDrawable(sd); 

yılında

ve düğmeye bastığınızda

public void pressMe(View view) { 
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main); 
    TextView tv = new TextView(MainActivity.this); 
    tv.setGravity(Gravity.CENTER); 
    tv.setTextSize(25); 
    tv.setPadding(0, 5, 0, 5); 
    tv.setText("TextView " + linearLayout.getChildCount()); 
    linearLayout.addView(tv); 
} 

sonuç bunun için

enter image description here

+0

teşekkürler olduğunu. Emülatörü düşünmedim. –

+0

Sadece bir telefonda test ettim ve sorun yok. Süre dolduğunda ödül kazanacak, umarım biraz daha oy alırsınız. –

+0

size bekliyoruz – Blackbelt