I have in Android/Java/Eclipse a Flag Guess Game: appear a name of country and below 3 or 6 or 9 flags (depend on settings) in 1 or 2 or 3 rows respecively to, choose the flag for the country name...well something wrong exist and flags appear some very big and others very-very small... eg rather appear 3 in the same row normally...

flags 99% have width 480px and height 235-333px ... Nepal is 400x480px...etc what is the trick to insert 3 flags in a row (table) in about each in 150dp x 100dp WxH...?

      // get a reference to the LayoutInflater service
      LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      // add 3, 6, or 9 answer Buttons based on the value of guessRows
      for (int row = 0; row < guessRows; row++) 
      {
         TableRow currentTableRow = getTableRow(row);

         // place Buttons in currentTableRow
         for (int column = 0; column < 3; column++) 
         {
            // inflate guess_button.xml to create new Button
                 ImageView newGuessButton = (ImageView) inflater.inflate(R.layout.guess_flag, null);
                 newGuessButton.setAdjustViewBounds(false);
            // get country name and set it as newGuessButton's text
            String fileName = fileNameList.get((row * 3) + column);
            setFlag(fileName, newGuessButton);  

            // register answerButtonListener to respond to button clicks
            newGuessButton.setOnClickListener(guessButtonListener);
            currentTableRow.addView(newGuessButton);
         } // end for
      } // end for

      // randomly replace one Button with the correct answer
      int row = random.nextInt(guessRows); // pick random row
      int column = random.nextInt(3); // pick random column
      TableRow randomTableRow = getTableRow(row); // get the TableRow
      //String countryName = getCountryName(correctAnswer);
      //((ImageView)randomTableRow.getChildAt(column)).setText(countryName);  

      setFlag(correctAnswer, ((ImageView)randomTableRow.getChildAt(column)));
   } // end method loadNextFlag



   private void setFlag(String nextImageName, ImageView newGuessButton)
   {   
   // extract the region from the next image's name
   String region = nextImageName.substring(0, nextImageName.indexOf('-'));

   // use AssetManager to load next image from assets folder
   AssetManager assets = getAssets(); // get app's AssetManager
   InputStream stream; // used to read in flag images

   try
   {
      // get an InputStream to the asset representing the next flag
      stream = assets.open(region + "/" + nextImageName + ".png");

      // load the asset as a Drawable and display on the flagImageView
      Drawable flag = Drawable.createFromStream(stream, nextImageName);
      newGuessButton.setImageDrawable(flag); 
      newGuessButton.setContentDescription(nextImageName); 
   } // end try
   catch (IOException e)  
   {
      Log.e(TAG, "Error loading " + nextImageName, e);
   } // end catch

}





R.layout.guess_flag
   <?xml version="1.0" encoding="UTF-8"?> 
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/newGuessButton" 
      android:adjustViewBounds="false" 
      android:layout_width="@dimen/flag_width2"
      android:layout_height="@dimen/flag_height2"
      android:contentDescription="@string/imgToGuess"></ImageView>


<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title_size">25sp</dimen>
   <dimen name="flag_width">227dp</dimen>
   <dimen name="flag_height">150dp</dimen>
   <dimen name="answer_size">40sp</dimen>
   <dimen name="text_size">20sp</dimen>
   <dimen name="flag_height2">90dp</dimen>
   <dimen name="flag_width2">131dp</dimen>
</resources>

device-2012-10-09-224929

see attachment my code result...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.