ビューから拡張されたカスタムビュークラスがあり、アクティビティで使用したいのですが、何も表示されません。実行中にエラーは発生しませんが、黒い画面には出力がありません。私のコードは次のとおりです。
public class MoveableMenuLayout extends View {
public MoveableMenuLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LinearLayout ll = new LinearLayout(context);
ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TextView tv = new TextView(context);
tv.setText("TES_______________");
ll.addView(tv);
this.invalidate();
this.requestLayout();
}
public MoveableMenuLayout(Context context) {
super(context);
LinearLayout ll = new LinearLayout(context);
ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TextView tv = new TextView(context);
tv.setText("TES_______________");
ll.addView(tv);
this.invalidate();
this.requestLayout();
}
}
呼び出しアクティビティ
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MoveableMenuLayout layout = new MoveableMenuLayout(this);
setContentView(layout);
}
}
xmlレイアウトに含めて試しましたが、まだ出力されません。何が間違っているのかわかりません。別のクラスにしたいスタイルを変更したくありません。xmlレイアウトを使用して、setcontentviewを使用してActivityに直接設定できることはわかっていますが、そのようにはしたくありません。ありがとう