Skip to content
Snippets Groups Projects
Commit db5fa5ee authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Ex 2 - 1

parent dc4e5b91
Branches
No related tags found
No related merge requests found
......@@ -16,10 +16,15 @@ import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ConstraintLayout myLayout;
private ConstraintSet set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
configureLayout();
exercice2();
}
private int convertToPx(int value) {
......@@ -35,7 +40,7 @@ public class MainActivity extends AppCompatActivity {
myButton.setText(getString(R.string.press_me));
myButton.setBackgroundColor(Color.YELLOW);
ConstraintLayout myLayout = new ConstraintLayout(this);
myLayout = new ConstraintLayout(this);
myLayout.setBackgroundColor(Color.BLUE);
myButton.setId(R.id.myButton);
......@@ -63,7 +68,7 @@ public class MainActivity extends AppCompatActivity {
myLayout.addView(myTextView);
setContentView(myLayout);
ConstraintSet set = new ConstraintSet();
set = new ConstraintSet();
// Contraintes bouton
set.constrainHeight(myButton.getId(),
......@@ -95,4 +100,26 @@ public class MainActivity extends AppCompatActivity {
set.applyTo(myLayout);
}
private void exercice2(){
// Exercice 2
Button bottomRightBtn = new Button(this);
bottomRightBtn.setText(getString(R.string.press_me));
bottomRightBtn.setBackgroundColor(Color.RED);
bottomRightBtn.setId(R.id.bottomRightBtn);
myLayout.addView(bottomRightBtn);
set.constrainHeight(bottomRightBtn.getId(),
ConstraintSet.WRAP_CONTENT);
set.constrainWidth(bottomRightBtn.getId(),
ConstraintSet.WRAP_CONTENT);
set.connect(bottomRightBtn.getId(), ConstraintSet.RIGHT,
ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
set.connect(bottomRightBtn.getId(), ConstraintSet.BOTTOM,
ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0);
set.applyTo(myLayout);
}
}
\ No newline at end of file
......@@ -2,4 +2,5 @@
<resources>
<item name="myButton" type="id" />
<item name="myEditText" type="id" />
<item name="bottomRightBtn" type="id" />
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment