Witam, dopiero zacząłem się uczyć android studio z tutorialem buckiego robertsa na yt. Mam identyczny (chyba) kod jak on i nie działa mi pozycjonowanie, czyli w skrócie chcę ustawić mój przycisk na środku ekranu. Pomoże ktoś? Oto kod w javie:
package com.example.bercik.allison;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.Button;
import android.graphics.Color;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Layout
RelativeLayout bercikLayout = new RelativeLayout(this);
bercikLayout.setBackgroundColor(Color.GREEN);
RelativeLayout.LayoutParams buttonDetails = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL);
buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL);
// Button
Button redButton = new Button(this);
redButton.setText("Click");
redButton.setBackgroundColor(Color.RED);
// Add widget to layout(button is now a child of layout)
bercikLayout.addView(redButton);
// Set this activities content/display to this view
setContentView(bercikLayout);
}
}
Edit: w xml'u tez nie działa ...Wszystko nakłada się na siebie ...
