1

以下のコードを使用してシステム レイアウトで画像を表示できることはわかっていますが、カスタム レイアウトで画像を表示したいのですが、どうすればよいですか? ありがとう!

public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int id = v.getId();
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*");
                    startActivityForResult(intent,ForBrowse);
}



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border_ui"
    android:orientation="vertical"
    android:paddingTop="3dip" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Button
        android:id="@+id/btnClose"
        style="@style/myTextAppearance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/myreturn" />

</LinearLayout>
4

4 に答える 4

1

あなたが行ったようにxmlを設定した後、

次のコードを追加して、画像をイメージビューに設定するだけです

ImageView img = (ImageView)findViewById(R.id.Imageview1);
img.setImageResource(R.drawable.yourimage);
于 2013-07-22T07:46:15.037 に答える
1

上記の解像度が適切でない場合は、これを試してください。必要なページから画像が読み込まれます。

String url = "file://" + arrPath[id]), "image/*";
Bitmap bmp = fromURL(url);
imgview.setImageBitmap(bmp);
and write this function:

public static Bitmap fromURL(String src) {  
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap mybitmap = BitmapFactory.decodeStream(input);

            return bitmap;

        } catch (Exception exception1) {
            return null;
        }
于 2013-07-22T07:51:51.813 に答える