I am trying to create a contentView programmatically and i cannot understand why the following code dows not work as i want. Here is the code:
public class UserProfile extends AppCompatActivity {
ScrollView scrollView;
LinearLayout contentnView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
ServerRequest serverRequest = new ServerRequest(this);
final String userid = intent.getStringExtra(PostPopUp.EXTRA_USER_PROFILE_ID);
serverRequest.getUserPostsInBackground(userid, new GetCallback() {
@Override
public void done(ArrayList<Document> docs) {
contentnView = new LinearLayout(UserProfile.this);
contentnView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentnView);
RelativeLayout relativeLayoutWithView = new RelativeLayout(UserProfile.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
relativeLayoutWithView.setLayoutParams(params);
relativeLayoutWithView.setPadding(16, 16, 16, 16);
relativeLayoutWithView.setBackgroundColor(Color.WHITE);
FacebookSdk.sdkInitialize(getApplicationContext());
ProfilePictureView profilePictureView = new ProfilePictureView(UserProfile.this);
profilePictureView.setProfileId(userid);
profilePictureView.setId(View.generateViewId());
final HashMap<Integer, View> lines = new HashMap<>();
int i = 0;
for (Document post : docs) {
lines.put(i, new View(UserProfile.this));
i++;
}
RelativeLayout.LayoutParams paramsProfileImg = new RelativeLayout.LayoutParams(170, 170);
paramsProfileImg.addRule(RelativeLayout.CENTER_HORIZONTAL, 1);
relativeLayoutWithView.addView(profilePictureView, paramsProfileImg);
for (int j = 0; j < textViews.size(); j++) {
RelativeLayout.LayoutParams paramsLine = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
if (j == 0) {
paramsLine.addRule(RelativeLayout.BELOW, profilePictureView.getId());
} else {
paramsLine.addRule(RelativeLayout.BELOW, lines.get(j - 1).getId());
}
paramsLine.setMargins(0, 16, 0, 0);
lines.get(j).setLayoutParams(paramsLine);
relativeLayoutWithView.addView(lines.get(j), paramsLine);
}
scrollView = new ScrollView(UserProfile.this);
scrollView.addView(relativeLayoutWithView);
contentnView.addView(scrollView);
}
});
}
}
What i want is the first view (which is just a line like hr btw) to align below profile picture view (which it does) and the other views to align one below the other. What does happen is that the first view aligns below profile picture view and all the others are stack to start of the screen.
Any ideas?
.. serverRequest.getUserPostsInBackground is just an AsynkTask