0

画面にボタンがあり、そのボタンをクリックするとカメラが開き、その後写真を撮るアプリケーションを開発したいと思います。ボタンがあるレイアウトが拡大し、写真がこのボタンの下に来ます。

このことを、スクリーン ショットの 1 つのアプリケーションで示します。

ここに画像の説明を入力

ここで写真をクリックすると、写真がキャプチャされ、このレイアウトが展開され、写真がこのようにすぐ下に表示されます:-

ここに画像の説明を入力 ここに画像の説明を入力

アプリケーションで同じことが必要です。

このために、私はいくつかのコードを試しました:-

(TableLayout にある TableRow のアプリケーションには、既にいくつかのフィールドがあります)

最初に tableRow1 (たとえば) を 1 つ作成し、次に TableLayout を 1 つ作成し、次にボタン用に TableRow2 を 1 つ、Image 用に TableRow3 を 1 つ作成します。ボタンを tableRow2 に挿入し、この tableRow2 を TableLayout に挿入してから、TableLayout を tableRow1 に挿入します。写真をキャプチャした後、Image を TableRow3 に挿入し、この tableRow3 を TableLayout に挿入します。

しかし、このコードは機能しません。このコードもエラーを出しません。

コード:

tableRow1 = new TableRow(this);
tableRow1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

tableLayout = new TableLayout(this);
tableRow2 = new TableRow(this);

tableLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tableRow2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

buttonPhoto = new Button(this);
buttonPhoto.setText("Photo");
buttonPhoto.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

tableRow2.addView(buttonPhoto);

tableLayout.addView(tableRow2, new TableLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

tableLayoutMain.addView(tableLayout, new TableLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));



buttonPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            method1();
        }
    });

public void method1(){

    tableRow3 = new TableRow(this);

    tableRow3.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    imageViewPhoto = new ImageView(this);
    imageViewPhoto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 110));
    tableRow3.addView(imageViewTakePhoto);

    tableLayout.addView(tableRow3, new TableLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}

このコードを使用すると、画面にボタンが表示されなくなります。

4

1 に答える 1

0

LayoutParamsに追加するビューにも適切なを使用してみてくださいTableRows:

tableRow1 = new TableRow(this);
tableRow1.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableLayout = new TableLayout(this);
tableRow2 = new TableRow(this);
buttonPhoto = new Button(this);
buttonPhoto.setText("Photo");
buttonPhoto.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow2.addView(buttonLocationPhoto);
tableLayout.addView(tableRow2, new TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
buttonPhoto.setOnClickListener //...

そして方法:

public void method1(){
    tableRow3 = new TableRow(this);
    imageViewPhoto = new ImageView(this);
    imageViewPhoto.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 110));
    tableRow3.addView(imageViewTakePhoto);
    tableLayout.addView(tableRow3, new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
}

また、あなたの質問では、 を に追加してから (まだレイアウトにない場合) をメイン テーブルに追加することについて話していることがtabLelayoutわかりtableRow1ますtableRow1。この場合:

tableRow1.addView(tableLayout, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
//add the tableRow1 to the main table?!?

ただし、コードではこれを行わず、代わりに次の行があります。

tableLayoutMain.addView(tableLayout, new TableLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
于 2012-12-21T20:23:20.130 に答える