图像比平常更小! Android-Java开发

时间:2014-04-23 10:27:34

标签: java android eclipse

我正在制作一个展示公司照片的应用程序,我在相对布局中创建了一个ImageView,并且还使用户可以逐个浏览图像。但是,它在Eclipse中看起来都很好(imageview与父级匹配等)但是当我在模拟器或我的设备上运行它时图像变得很小!我做错了什么?

这是我的页面XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Wedding" 
    android:background="#000000"
    android:orientation="vertical">

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

这是我的Java类:

package com.example.ijazphotography;

import android.os.Bundle;
import android.content.Context;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;



public class Wedding extends Activity {



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wedding);
    // Show the Up button in the action bar.
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    ImagePagerAdapter adapter = new ImagePagerAdapter();
    viewPager.setAdapter(adapter);
  }

  private class ImagePagerAdapter extends PagerAdapter {
        private int[] mImages = new int[] {
            R.drawable.wed11,
            R.drawable.wed15,
            R.drawable.wed16,
            R.drawable.wed17,
            R.drawable.wed2,
            R.drawable.wed20,
            R.drawable.wed23,
            R.drawable.wed24,
            R.drawable.wed4,
            R.drawable.wed5,
            R.drawable.wed6,
            R.drawable.wed7
        };

        public int getCount() {
            return mImages.length;
        }

        public boolean isViewFromObject(View view, Object object) {
            return view == ((ImageView) object);
        }
        public Object instantiateItem(ViewGroup container, int position) {
            Context context = Wedding.this;
            ImageView imageView = new ImageView(context);

            int padding = context.getResources().getDimensionPixelSize(
                R.dimen.padding_medium);
            imageView.setPadding(padding, padding, padding, padding);
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setImageResource(mImages[position]);
            ((ViewPager) container).addView(imageView, 0);
            return imageView;
          }
        public void destroyItem(ViewGroup container, int position, Object     object) {
            ((ViewPager) container).removeView((ImageView) object);
          }
  }
}

2 个答案:

答案 0 :(得分:1)

而不是

ScaleType.CENTER_INSIDE

使用

ScaleType.FIT_XY

使图像适合ImageView

正如您所问,ScaleType.FIT_XY是否适用于ImageButton?是的,它也适用于ImageButton

答案 1 :(得分:0)

那些宽度和高度设置不应该是&#34; fill_parent&#34;不是&#34; match_parent&#34;?