ゴール:50〜75のRelativeLayoutsを、プログラムで垂直LinearLayoutに追加しようとしています。各RelativeLayoutには2つのImageViewがある別のLinearLayoutがあります。そして、私はすべての画像を見えるようにし、同じサイズにします。LinearLayout内のすべてのアイテムをXamarin.Androidのレイアウト境界から外れないようにするにはどうすればよいですか?
問題:それらを追加しようとすると、約40のImageViewだけが表示され、残りは表示されません。
- 各RelativeLayoutには2つのイメージビューが含まれています。
- ImageViewsのすべての画像は、同じ高さと幅です。
- すべての画像が表示されている限り、アスペクト比が失われても問題ありません。
- LinearLayoutの一番上に余白があります。すべてのビューにはマージンがありません。
図:
マイアダプタ(ネイティブアダプタのいずれかを拡張しません)
private void LoadViews()
{
int amountOfRowsPerYear = 52/mmCalc.amountOfWeeksInARow;
for (int i = 0; i <= artifact.RowMetaList.Count; i += amountOfRowsPerYear)
{
cvWrapper = GetView(i, amountOfRowsPerYear);
parent.AddView(cvWrapper);
}
}
private RelativeLayout GetView(int position, int amountOfRowsPerYear)
{
LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
RelativeLayout convertView = (RelativeLayout)inflater.Inflate(Resource.Layout.ArtifactRowLayout, null);
if (amountOfRowsPerYear != 2)
throw new NotImplementedException("this mehtod can only accept 2 rows per year for now");
else if (amountOfRowsPerYear == 2)
{
int first = position;
int second = position + 1;
Artifact.RowMetaData row = artifact.RowMetaList[first];
Artifact.RowMetaData row2 = null;
try {row2 = artifact.RowMetaList[second];}catch (Exception ex){}
ImageView RowImageView = convertView.FindViewById<ImageView>(Resource.Id.RowImageView);
ImageView RowImageView2 = convertView.FindViewById<ImageView>(Resource.Id.RowImageView2);
RowImageView.SetImageBitmap(GetRowBitmap(row));
try { RowImageView2.SetImageBitmap(GetRowBitmap(row2)); } catch (Exception ex)
{ RowImageView2.Visibility = ViewStates.Gone; }
}
return convertView;
}
ArtifactRowLayout.axml(に膨張されるレイアウト上記のGetView()メソッド)。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/RowMainRL"
android:minWidth="25px"
android:minHeight="25px"
android:layout_weight="1.0">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout1">
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/RowImageView"
android:adjustViewBounds="false" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/RowImageView2"
android:adjustViewBounds="false"
android:src="@android:drawable/ic_menu_gallery" />
</LinearLayout>
ArtifactDisplayer.axml(ビューが膨張されている場合、ID/ArtifactLinearLayoutです)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:animateLayoutChanges="true"
android:theme="@style/MyTheme">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ArtifactLinearLayout"
android:layout_margin="20dp" />
</LinearLayout>
すべてのビューでさまざまな属性を試しましたが、解決策が見つかりませんでした。ビューの半分以上が限界を超えてしまいます。
また、ビューのそれぞれの正確な高さと幅をプログラム的に設定しようとしましたが、何らかの理由でこれを行っても目に見えません。
こんにちは、応答ありがとうございます。画像は低忠実度であり、小さくすることを意図している。幅は約1080px、高さは約42pxです。 –