1

ユーザーがドラッグアンドドロップで再配置できるように、画像とキャプションのペアのグリッドを作成しようとしています。これを行うには、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>
4

2 に答える 2

4

編集

はるかに優れたバージョンがここにあります。これは、アクティブな開発において、さらにいくつかの機能を備えたDraggableGridViewに基づいており、かなり安定しています。

元の投稿:
私はライブラリに取り組んでいます。現在、データベースを使用して希望どおりにライブラリを動作させており、ArrayAdapterへの移動に取り組んでいます。ここに私のフォークがあります

于 2012-08-10T20:45:46.093 に答える
1

DraggableGridView.java に 1 行のコードを追加すると、問題が修正されます。DraggableGridView.java を開き、次の行を追加します。

getChildAt(i).measure(MeasureSpec.makeMeasureSpec(childSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(childSize, MeasureSpec.EXACTLY));

getChildAt(i).layout(xy.x, xy.y, xy.x + childSize, xy.y + childSize);

それが役立つことを願っています。別の投稿リンクから解決策が見つかりました: Imageview と textview がビューに表示されませんか?

于 2015-11-04T12:43:35.063 に答える