0
プログラムでいくつかのビューを作成しようとしています。それは同じように見えるべきものです:Androidプログラムによって作成されたコンテンツが正しく表示されない
!
これは私が持っているものです。
!
これは私のレイアウトです:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="@+id/choose_activity_dialog_table_layout">
<TableRow>
<!-- ACTIVITY TYPE -->
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left">
<ImageView
android:layout_width="match_parent"
android:layout_height="40dp"
android:src="@drawable/pct_equitation_white"
android:scaleType="centerInside"
/>
<TextView
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:gravity="center"
android:textColor="@color/white"
/>
</RelativeLayout>
<!-- ACTIVITY TYPE -->
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="left"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="40dp"
android:src="@drawable/pct_amhe_white"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
/>
<TextView
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:gravity="center"
android:textColor="@color/white"
/>
</RelativeLayout>
<!-- ACTIVITY TYPE -->
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="left"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="40dp"
android:src="@drawable/pct_ecriture_white"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
/>
<TextView
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:gravity="center"
android:textColor="@color/white"
/>
</RelativeLayout>
</TableRow>
</TableLayout>
</LinearLayout>
これは私のループです:
View v = inflater.inflate(R.layout.choose_activity_dialog_view, container, false);
int count = 1;
TableRow row = new TableRow(getContext());
TableLayout mainLayout = (TableLayout) v.findViewById(R.id.choose_activity_dialog_table_layout);
for(UserActivity ua : HomeActivity.userActivityStore.getUserActivities()){
Activity currentActivity = HomeActivity.activityStore.findByActivityId(ua.getActivityId());
if(currentActivity == null)
continue;
if(count % 3 == 0){
count = 1;
mainLayout.addView(row);
row = new TableRow(v.getContext());
}
ImageView pictogramImageView = new ImageView(getContext());
final int pictogramImageViewWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
RelativeLayout.LayoutParams pictogramImageViewParams = new RelativeLayout.LayoutParams(pictogramImageViewWidth, RelativeLayout.LayoutParams.MATCH_PARENT);
pictogramImageView.setLayoutParams(pictogramImageViewParams);
pictogramImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
pictogramImageView.setImageDrawable(getResources().getDrawable(R.drawable.pct_amhe));
TextView activityNameTextView = new TextView(getContext());
RelativeLayout.LayoutParams activityNameLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
activityNameLayoutParams.setMargins(
0,
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()),
0,
0
);
activityNameTextView.setLayoutParams(activityNameLayoutParams);
activityNameTextView.setGravity(Gravity.CENTER);
activityNameTextView.setTextColor(Color.WHITE);
activityNameTextView.setText(currentActivity.getName());
RelativeLayout rowRelativeLayout = new RelativeLayout(getContext());
final int rowRelativeLayoutWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
TableRow.LayoutParams params = new TableRow.LayoutParams(rowRelativeLayoutWidth, TableRow.LayoutParams.WRAP_CONTENT, 1f);
rowRelativeLayout.setGravity(Gravity.LEFT);
rowRelativeLayout.setLayoutParams(params);
rowRelativeLayout.addView(pictogramImageView);
rowRelativeLayout.addView(activityNameTextView);
row.addView(rowRelativeLayout, count - 1);
count++;
}
mainLayout.addView(row);
私はこの問題は、ここで何、私は時間のトピックやものを探してきていないと私はちょうどそれを得ることができません..
目的のビューはxmlを使用して簡単にレイアウトできます。あなたがプログラムでそれをやりたがっている理由はありますか? – Elye