In a project in android studio, when clicking on one of the 2 buttons in activity (01 and 101) a TextView displays a response corresponding to the choice.
I would like to know how to create a new button just below this second TextView:
Iknowthefollowingreferencescanbemade(positionbeingthepositioningRelativeLayout):
Topleft=>position.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
Topright=>position.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Leftfooter=>position.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.ALIGN_PARENT_LEFT);
Rightfooter=>position.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.ALIGN_PARENT_RIGHT);
Vertical/horizontalcenter=>position.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.CENTER_HORIZONTAL);
BEYONDOTHER...
IlearnedthisthankstoAckLay'sanswertothisquestion#
But I did not find anything related to the reference to another component present in the activity.
MainActivity:
package genesysgeneration.chloko;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button btn01, btn101;
private TextView tv02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv02=(TextView)findViewById(R.id.tv02);
btn01=(Button)findViewById(R.id.btn01);
btn101=(Button)findViewById(R.id.btn101);
btn01.setOnClickListener(this);
btn101.setOnClickListener(this);
}
public void onClick(View v){
switch (v.getId()){
case R.id.btn01:
RelativeLayout relativeLayout01 = (RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams layoutParams01 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
Button btn02 = new Button(this);
btn02.setText("02");
relativeLayout01.addView(btn02, layoutParams01);
RelativeLayout.LayoutParams position01 = (RelativeLayout.LayoutParams) btn02.getLayoutParams();
//abaixo do TEXTVIEW (tv02)
break;
case R.id.btn101:
RelativeLayout relativeLayout02 = (RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams layoutParams02 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
Button btn102 = new Button(this);
btn102.setText("102");
relativeLayout02.addView(btn102, layoutParams02);
RelativeLayout.LayoutParams position02 = (RelativeLayout.LayoutParams) btn102.getLayoutParams();
//abaixo do TEXTVIEW (tv02)
break;
}
}
}
One thing that caught my eye was that in the statement of RelativeLayout.LayoutParams layoutParams01 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
I was not able to put the actual size of the height of my relativelayout which in this case is 3000dp , I had to put WRAP_CONTENT
.
I would like to know if there might be a problem if I have to create one more of these buttons and it is much lower in the activity.