0
私はImageViewとTextViewからなるRelativeLayoutを持っています。さて、このRelativeLayoutに、私はTextViewの下に整列されるはずのLinearLayoutを追加します。現在、LinearLayoutはRelativeLayoutに追加されていますが、TextViewの下には配置されていません。ここに私のコードです:プログラムでRelativeLayout内にLinearLayoutを追加するにはどうすればよいですか?
void addRatingToImage(RelativeLayout relativelLayout, Movies movieObject) {
ImageView ratingImageView;
LinearLayout ratingLayout = new LinearLayout(mContext);
ratingLayout.setOrientation(LinearLayout.HORIZONTAL);
double roundedRating = roundUpRating(Double.parseDouble(movieObject.mRating));
for(int i = 0; i < 5; i++) { //TODO: Check
ratingImageView = new ImageView(mContext);
if(i < roundedRating) {
ratingImageView.setBackgroundResource(R.drawable.star_2);
ratingLayout.addView(ratingImageView);
}
else {
ratingImageView.setBackgroundResource(R.drawable.star_1);
ratingLayout.addView(ratingImageView);
}
}
RelativeLayout.LayoutParams ratingLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
TextView movieNameTextView = (TextView)relativelLayout.getChildAt(2);
ratingLayoutParams.addRule(RelativeLayout.BELOW, movieNameTextView.getId());
ratingLayout.setLayoutParams(ratingLayoutParams);
relativelLayout.addView(ratingLayout);
}
私はここに1つの疑いがあります。 RelativeLayout.BELOWは、RelativeLayoutにネストされた別の種類のレイアウトに適用されても動作しますか?ありがとう。
RelativeLayout.Belowが機能することを通知してくれてありがとう。私はRelativeLayout.ALIGN_PARENT_BOTTOMを使ってそれを解決し、LinearLayoutをRelativeLayoutに揃えてからマージンを使用しました。しかし、TextView movieNameTextViewはWRAP_CONTENTに設定されています。私はそれを把握します。もう一度ありがとう。 – FireAndIce