Sto creando a livello di codice visualizzazioni di testo con linee orizzontali tra ogni vista. Utilizzando un drawable creato a livello di codice.Opacità incrementale, con opacità costante Visualizzazione immagine con Drawable
Il problema è che l'opacità inizia a lampeggiare e aumenta gradualmente per ogni linea.
Ho registrato l'opacità (getAlpha()) di drawable, paint, image view e layout lineare in tutti i punti nei due metodi forniti e dai drawable è sempre 255 e le viste 1.0. Non capisco perché non si comporti come se fosse vero. Ho anche provato ad impostare Alpha, non fa differenza.
Perché sta facendo questo e come lo risolvo?
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:
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;
}
Grazie per questo. Non pensavo all'emulatore. –
Appena testato su un telefono, va bene. Otterrai un premio quando il periodo scadrà, si spera che otterrai più voti. –
siete i benvenuti – Blackbelt