Vote count:
0
I have a custom View
class in Android, which is to display nothing in the beginning, but only draw its content as soon as show()
has been called on it.
I've checked this on Android 4.1 and 4.4, and it seems to work. However, some users with Android KitKat (e.g. on a Samsung Galaxy S4), have reported that nothing is ever drawn in this View
. What could be the reason for that? (The full code can be found here.)
Usage in XML:
<com.my.package.MyView
android:id="@+id/my_view"
android:layout_width="48dp"
android:layout_height="48dp" />
Usage in Java:
MyView myView = (MyView) findViewById(R.id.my_view);
myView.show(42);
Referenced class MyView
in Java:
public class MyView extends View {
public MyView(Context context) {
super(context);
init();
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
protected void init() {
setWillNotDraw(true);
}
public void show(int input) {
// do some initialization so that onDraw() knows what to draw
setWillNotDraw(false);
// invalidate() doesn't seem to be necessary (no effect)
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// draw things on the canvas now
}
}
asked 22 secs ago
Aucun commentaire:
Enregistrer un commentaire