2013-08-26 3 views
0

내 코드의이 부분에서 이미지를 클릭 할 때이를 변경하고 싶습니다. 내가 어떻게 할 수 있니?이미지 크기를 변경하는 방법

나는 img.setOnClickListenser 사용하지만 정말 내가 그것을

 @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.gallery_img2, container, false); 
      Log.d("start_new_frg gallery_img ", "ok"); 
      back = (Button)rootView.findViewById(R.id.button1); 

      if (id == -1){ 

       Toast.makeText(getActivity(), "bad Entry ", Toast.LENGTH_LONG).show(); 
       onBackPressed(); 
       getActivity().finish(); 

      } 


      imgv = (ImageView) rootView.findViewById(R.id.imageView1); 

      String ROOT = Environment.getExternalStorageDirectory().getPath()+"/POSTSIMAGES/"; 
      final Bitmap image = BitmapFactory.decodeFile(ROOT+String.valueOf(g.getId())+"q.jpg"); 


      File f = new File(ROOT+String.valueOf(g.getId())+"q.jpg"); 
      temp=ROOT; 
      if(!f.exists()){ 
       imgv.setImageResource(R.drawable.logo_and); 
       } 
      else 
      { 
       imgv.setImageBitmap(image); 

      } 
      if(isNetworkConnected()){ 

       new conn().execute(""); 

      }else{ 
      // pd.dismiss(); 

    //  if(ROOT.endsWith("_s")) 
    //  { 
    //  
    //   
    //  } 
       imgv.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        // your code here 
        Log.d("inside onclick", "ok"); 
        String _n=temp.replace("_s.jpg", "_n.jpg"); 
        imageLoader2.DisplayImage(_n,imgv); 
      // imgv.setScaleType(ImageView.ScaleType.FIT_XY); 

       } 
      }); 

      } 

      //////////////////////// ADS /////////////////////// 

     // Create the adView 
      adView = new AdView(getActivity(), AdSize.SMART_BANNER, "a150f45ea765784"); 

      // Lookup your LinearLayout assuming it's been given 
      // the attribute android:id="@+id/mainLayout" 
      LinearLayout layout = (LinearLayout)rootView.findViewById(R.id.ADS); 

      // Add the adView to it 
      layout.addView(adView); 

      // Initiate a generic request to load it with an ad 
      adView.loadAd(new AdRequest()); 
    //////////////////////// END ADS /////////////////////// 

      back.setOnClickListener(new OnClickListener() { 

       public void onClick(View arg0) { 
        Fragment newFragment = new Gallery(getActivity()); 
        FragmentTransaction transaction = getFragmentManager().beginTransaction(); 

        // Replace whatever is in the fragment_container view with this fragment, 
        // and add the transaction to the back stack 
        transaction.replace(android.R.id.content, newFragment); 
       // transaction.addToBackStack(null); 

        // Commit the transaction 
        // transaction.remove(mFragment); 
        transaction.commit(); 


       } 
      }); 

      return rootView; 

     } 

답변

0

이 하나

final Bitmap image = BitmapFactory.decodeFile(ROOT+String.valueOf(g.getId())+"q.jpg"); 
Bitmap bitmapimage = Bitmap.createScaledBitmap(image, 60, 60, true); 

시도에 코드를 넣어해야하는지 모르거나 이미지의이 방법의 패스 경로를 호출 할 수 있으며, 폭 및 높이의 크기는 60 및 60과 같습니다.

public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, 
      int reqHeight) { 

     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(path, options); 

     options.inSampleSize = calculateInSampleSize(options, reqWidth, 
       reqHeight); 

     // Decode bitmap with inSampleSize set 
     options.inJustDecodeBounds = false; 
     Bitmap bmp = BitmapFactory.decodeFile(path, options); 
     return bmp; 
     } 

    public static int calculateInSampleSize(BitmapFactory.Options options, 
      int reqWidth, int reqHeight) { 

     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 1; 

     if (height > reqHeight || width > reqWidth) { 
      if (width > height) { 
       inSampleSize = Math.round((float) height/(float) reqHeight); 
      } else { 
       inSampleSize = Math.round((float) width/(float) reqWidth); 
      } 
     } 
     return inSampleSize; 
     } 
+0

나는이 코드 조각을 넣어, 또는 내가 일을하기 위해 몇 가지 여분의 일을해야 하는가? ,, 필자는 그냥 넣어 지금 –

+0

그냥 하나 개의 이미지 당신이 원하는 코드를 넣어 전까지 작동하지 않습니다 –

+0

크기를 조정하려면 2 곳을 넣고 여전히 작동하지 않습니다. 먼저 비트 맵 선언 아래에 두 번째 부분을 입력하고 작동하지 않습니다. –

0

동일한 코드를 사용하여 다른 비트 맵을 만듭니다. 원하는 이미지를 Imageview에 할당하십시오.

imgv.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      // your code here 
     final Bitmap new_image = BitmapFactory.decodeFile(ROOT+String.valueOf(g.getId())+"q.jpg"); 
     imgv.setImageBitmap(new_image); 
     } 
     }); 
+0

나는 그것을하려고 노력한다. 안돼요 onclick 메서드를 볼 로그 문을 로그에 표시되지 않습니다 고양이 –

+0

그게 효과가 있었나요? –

관련 문제