ユーザーがドラッグアンドドロップで再配置できるように、画像とキャプションのペアのグリッドを作成しようとしています。これを行うには、DraggableGridView - https://github.com/thquinn/DraggableGridViewを使用しています。
TextView と ImageView を表示して並べ替えることができますが、それらを 1 つのレイアウトに接続しようとすると、すべてが表示されなくなります。
したがって、画像とキャプションを含む XML を解析した後、次のように動作します。
for(ImagePair pair : pairs){
tv = new TextView(this);
tv.setText(pair.getText());
URL imageURL = new URL(pair.getURL());
Bitmap bmp = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
imv = new ImageView(this);
imv.setImageBitmap(bmp);
dgv.addView(tv);
dgv.addView(imv);
また、テキストと画像のグリッドが表示されますが、それらはペアではありません-テキストの場所を画像などで切り替えることができます.
画像+テキストを含むレイアウトを挿入しようとすると:
for(ImagePair pair : pairs){
Bitmap bmp = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
LayoutInflater li = getLayoutInflater();
View v = li.inflate(R.layout.image, null);
TextView txtv = (TextView)v.findViewById(R.id.ltext);
txtv.setText(pair.getText());
ImageView iv = (ImageView)v.findViewById(R.id.limage);
iv.setImageBitmap(bmp);
dgv.addView(v);
何も表示されません。実行することで、任意の単一のビューを表示できます
this.setContentView(v);
画像とキャプションのペアは適切に表示されますが、それらをグリッドに挿入しようとすると、グリッドが 9 人の子が存在することを報告しているにもかかわらず、黒い画面が表示されます。
私が使用しているレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/limage"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/ltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColorHighlight="#656565">
</TextView>
</TableRow>
</TableLayout>