三星galaxy S7中的图像看起来非常小

时间:2017-02-21 12:41:25

标签: android xml

在我的应用程序中,我从JSON获取图像并将其显示在图库中。在单击每个图像时,它会扩展为完整活动,它通常看起来像这样。 Pic one

但是当我在Galaxy S7 Edge上测试它时,单个图像看起来很小,我不喜欢它与Nougat。

Pic Two

我该如何解决这个问题。

我发布我的代码

public class Displaydemo extends FragmentActivity {

static int NUM_ITEMS = 3;
static int pos ;
Button Img_Sel;
ProgressDialog pDialog;
public static String sel_img;

ImageFragmentPagerAdapter imageFragmentPagerAdapter;
ViewPager viewPager;
public static RequestQueue mRequestQueue;
public static ImageLoader mImageLoader;
public static NetworkImageView niv1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.displaydemo);
    NUM_ITEMS= getIntent().getIntExtra("count",0);
    pos=getIntent().getIntExtra("pos", 0);
    getImageLoader();
    Img_Sel=(Button)findViewById(R.id.Img_select);

    imageFragmentPagerAdapter = new ImageFragmentPagerAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.pagerdemo);

    viewPager.setAdapter(imageFragmentPagerAdapter);
    viewPager.setCurrentItem(pos);

}

public static class ImageFragmentPagerAdapter extends FragmentPagerAdapter {
    public static int p=0;
    public ImageFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return NUM_ITEMS;
    }

    @Override
    public Fragment getItem(int position) {

        p=position;
        SwipeFragment fragment = new SwipeFragment();
        return SwipeFragment.newInstance(p);
    }
}

public static class SwipeFragment extends Fragment {
    public static NetworkImageView imgNetWorkView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View swipeView = inflater.inflate(R.layout.swipe_fragment, container, false);
        Bundle bundle = getArguments();
        imgNetWorkView = (NetworkImageView) swipeView.findViewById(R.id.imgNetwork);

        int position = bundle.getInt("position");
        final String imgResId= Datas.imageIds[position];

      Toast.makeText(getActivity(),imgResId,Toast.LENGTH_LONG).show();
        imgNetWorkView.setImageUrl(imgResId, mImageLoader);

        Displaydemo.sel_img=""+position;
        String imgsel = imgResId;


        imgNetWorkView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), GalleryActivity.class);
                Bundle args = new Bundle();
                String ur = null;
                ur =imgResId;
                args.putString("URL", ur);
                intent.putExtras(args);
                startActivity(intent);
            }
        });
        return swipeView;
    }
    static SwipeFragment newInstance(int position) {
        SwipeFragment swipeFragment = new SwipeFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        swipeFragment.setArguments(bundle);
        return swipeFragment;
    }
}

XML

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:gravity="center">

<android.support.v4.view.ViewPager
    android:id="@+id/pagerdemo"
    android:layout_width="fill_parent"
    android:scaleType="fitCenter"
    android:background="@android:color/transparent"
    android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>

1 个答案:

答案 0 :(得分:0)

使用显示android:adjustViewBounds="true"上的图片的ImageView ViewPager属性。 并将ImageView的宽度设为match_parent