Pergunta

I have been able to successfully set up the Android Audio Capture example in my Eclipse.

But, in this part of the code:

ll.addView(mRecordButton,
            new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                0));

What do I need to do in order to place it at 20dp from top? I also cannot understand what the role of "0" is.

I tried to find answers here and here. Other stackoverflow posts about adding button programmatically do not answer my question and I do not have enough reputation to comment there.

Foi útil?

Solução

You could do this

LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

llParams.setMargins(0, 20, 0, 0);

ll.addView(mRecordButton, llParams);

Or you could try calling setPadding(0, 20, 0, 0) on mRecordButton before passing it into addView.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top