문제

As far as I understand, android widgets need RemoteViews, instead of View, like activities.

My question: is there any way to completely avoid xml, and build the whole layout with java code?

Alternative question: can I somehow retrieve a View, like I would use findViewById(int)? For example: LinearLayout linearLayout=(LinearLayout)findViewById(R.id.xxx); This way I could access the base layout, and manipulate however I want to.

Thanks!

도움이 되었습니까?

해결책

is there any way to completely avoid xml, and build the whole layout with java code?

No, sorry. RemoteViews relies heavily on layout XML resources. While there is an addView() method, it turns around and adds another RemoteViews, and that puts you right back where you started from.

can I somehow retrieve a View, like I would use findViewById(int)?

No, because there is no View in your process. You configure the widgets via the various setter methods on RemoteViews.

다른 팁

You can take Linear Layout pragmatically like
LinearLayout mLinearLayout = new LinearLayout(this);

also you can add its chilld using

Button mButton = new Button(this);   

mLinearLayout.addView(mButton);

setContentView(mLinearLayout);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top