title: ViewFlipper - How to Center my ImageView
body: <p>I have a viewflipper in which it has images, my problem is the image(an imageview) is not centered. I've solving it for hours and unfortunately not working. I can't find setGravity or gravity in imageview. here's my not working code:</p>
  
  <p>My Layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  &gt;
  &lt;ViewFlipper android:id="@+id/flipper" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_gravity="center"   
      android:scaleType="centerInside"
      android:background="#000000"
  &gt; 
  &lt;/ViewFlipper&gt;
  </code></pre>
  
  <p> </p>
  
  <p>In my src file:</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
       View view = inflater.inflate(R.layout.slider_image, container, false);      
  
       viewFlipper = (ViewFlipper)view. findViewById(R.id.flipper);
       desc = (TextView)view.findViewById(R.id.textDesc);
       desc.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum " +
              "libero dapibus mi semper accumsan. Vestibulum tortor diam, " +
              "imperdiet in consectetur faucibus, vulputate eget turpis." +
              " Nullam nec aliquet arcu. Nunc pretium nulla non nulla pulvinar " +
              "ac interdum risus dictum. Morbi viverra condimentum elit sit amet lobortis.");
       desc.setMovementMethod(new ScrollingMovementMethod());
       for(int i=0;i&lt;mThumbIds.length;i++)
       {
           setFlipperImage(mThumbIds[i]);
       }
       viewFlipper.setAutoStart(true);
       viewFlipper.setFlipInterval(8000);
       viewFlipper.setPadding(20, 10, 20,0);
       viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.view_right_in));
       viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_right_out));
       viewFlipper.startFlipping();
  
       viewFlipper.setOnTouchListener(new OnTouchListener(){
  
           public boolean onTouch(View arg0, MotionEvent arg1) {
  
               switch (arg1.getAction()){
  
                      case MotionEvent.ACTION_DOWN:{
                          downXValue = arg1.getX();
                          break;
                      }
  
                      case MotionEvent.ACTION_UP:{
                          float currentX = arg1.getX();            
                          if (downXValue &lt; currentX)
                          {
                               viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.view_right_in));
                               viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_right_out));
                               viewFlipper.showPrevious();
                          }
                          if (downXValue &gt; currentX)
                          {
                              viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_left_in));
                              viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_left_out));
                              viewFlipper.showNext();
                          }
                          break;
                      }
                }
               return true;
           }
       });
  
       super.setMenuVisibility (true);
       super.setHasOptionsMenu(true);
  
       return view; 
   }
  </code></pre>
  
  <p>My setflipper function:</p>
  
  <pre><code>private void setFlipperImage(int res) {
  
      ImageView image = new ImageView(getActivity().getApplicationContext());
  
      image.setBackgroundResource(res);
      @SuppressWarnings("deprecation")
      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(  LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
      image.setLayoutParams(layoutParams);
      image.setMaxHeight(350);
      image.setMaxWidth(600);
      image.setAdjustViewBounds(true);
      image.getLayoutParams().height = 350;
      image.getLayoutParams().width = 350;
      viewFlipper.addView(image);
  }
  </code></pre>
  
  <p>Any help is much appreciated.</p>