0
權我有相對佈局:的Android的RelativeLayout到的programmaticaly
<RelativeLayout
android:id="@+id/show_photo_details_comment_who_liked"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/show_photo_details_comment_who_liked_star"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:src="@drawable/photo_rate_on" />
</RelativeLayout>
,並希望一些文本視圖添加進去,我想將它們放在旁邊的ImageView ...
ImageView img = (ImageView) findViewById(R.id.show_photo_details_comment_who_liked_star);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.show_photo_details_comment_who_liked);
RelativeLayout.LayoutParams youParam = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
youParam.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
youParam.addRule(RelativeLayout.RIGHT_OF, img.getId());
youParam.setMargins(10,0,0,0);
TextView tv = new TextView(getApplicationContext());
tv.setLayoutParams(youParam);
tv.setText(getString(R.string.who_liked_you));
tv.setTextColor(getResources().getColor(R.color.green));
rl.addView(tv);
youParam.addRule(RelativeLayout.RIGHT_OF, tv.getId());
youParam.setMargins(0,0,0,0);
tv = new TextView(getApplicationContext());
tv.setLayoutParams(youParam);
tv.setText(",");
tv.setTextColor(Color.BLACK);
rl.addView(tv);
但是所有的意見都會出現在左上角。有誰能夠幫助我 ?