0
In an android studio project, when clicking on one of the 2 existing Textview on Activity (01 and 101) a Textview displays a corresponding answer to the choice.
I would like to know how to make a new button to be created just below that second Textview (answer):
I know that the following references can be made (being position o Relativepositioning layout):
Top left => position.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
Top right => position.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Left footer => position.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.ALIGN_PARENT_LEFT);
Right footer => position.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.ALIGN_PARENT_RIGHT);
Vertical/horizontal centre => position.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.CENTER_HORIZONTAL);
OTHER THAN OTHERS...
I learned that thanks to Ack Lay’s answer to that question How to create a textView by code in a specific Activity location?
However I did not find anything related to the reference to another company present in 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 struck me was that in the statement of RelativeLayout.LayoutParams layoutParams01 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
I could not put the real dimension of the height of my relativelayout which in the case is 3000dp, I had to put in WRAP_CONTENT
.
I wonder if there may be any problem if I have to create one more of these Buttons and the same is much further down on Activity.