Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing pageviewer with custom layout in android
    primarykey
    data
    text
    <p>i am new to android and while gallery is being showing as depreciated try to use the viewpager concept to dynamically loading custom layout which consist of imageview and textview everything is going great but while loading the viewpager the image appear to left and right side of the viewpager and showing large space so the question is how can we remove the space in between the page or view while using viewpager. here is the screenshot what i try to achieve: <img src="https://i.stack.imgur.com/MF24k.png" alt="enter image description here"></p> <p>and here is what i am getting :</p> <p><img src="https://i.stack.imgur.com/RjpUT.png" alt="enter image description here"></p> <p>so as u see the red circled two image are those image which is adding to the viewpager and there is lot of space in between two image.</p> <p>mentioning the pageadapter class where the image and text are there</p> <pre><code>public class ImagePagerAdapter extends PagerAdapter { private ArrayList&lt;Integer&gt; filter_image_arr; private ArrayList&lt;String&gt; filter_desc; private Context mcontext; private LayoutInflater inflator; private View layout; private TextView filter_title; private ImageView filter_image; public ImagePagerAdapter(Context context) { // TODO Auto-generated constructor stub mcontext=context; /* * add image to the arraylist */ filter_image_arr=new ArrayList&lt;Integer&gt;(); filter_image_arr.add(R.drawable.cakenormal); filter_image_arr.add(R.drawable.blur); filter_image_arr.add(R.drawable.emboss); filter_image_arr.add(R.drawable.gray); filter_image_arr.add(R.drawable.hue); filter_image_arr.add(R.drawable.monochrome); filter_image_arr.add(R.drawable.nored); filter_image_arr.add(R.drawable.oil); filter_image_arr.add(R.drawable.pixellate); filter_image_arr.add(R.drawable.posterize); filter_image_arr.add(R.drawable.sepia); filter_image_arr.add(R.drawable.vibrance); filter_image_arr.add(R.drawable.vintage); /* * add the desc for the filter effect.... * */ filter_desc=new ArrayList&lt;String&gt;(); filter_desc.add("NORMAL"); filter_desc.add("BLUR"); filter_desc.add("EMBOSS"); filter_desc.add("GRAY"); filter_desc.add("HUE"); filter_desc.add("MONOCHROME"); filter_desc.add("NO RED"); filter_desc.add("OIL"); filter_desc.add("PIXELATE"); filter_desc.add("POSTERIZE"); filter_desc.add("SEPIA"); filter_desc.add("VIBRANCE"); filter_desc.add("VINTAGE"); inflator=(LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public Object instantiateItem(ViewGroup container, int position) { // TODO Auto-generated method stub layout=inflator.inflate(R.layout.custom_gallery_item_layout, null); filter_image=(ImageView) layout.findViewById(R.id.filter_image); filter_image.setImageResource(filter_image_arr.get(position)); filter_image.setScaleType(ImageView.ScaleType.FIT_START); int padding=mcontext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin); filter_image.setTag(position); //filter_image.setPadding(padding, padding, padding, padding); filter_title=(TextView) layout.findViewById(R.id.filter_desc); filter_title.setText(filter_desc.get(position)); filter_title.setTag(position); ((ViewPager)container).addView(layout, 0); return layout; } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0==((View)arg1); } @Override public int getCount() { // TODO Auto-generated method stub return filter_image_arr.size(); } @Override public void destroyItem(ViewGroup container, int position, Object object) { // TODO Auto-generated method stub ((ViewPager)container).removeView((View)object); } } </code></pre> <p>and here is the activity class where adding adapter to the viewpager</p> <pre><code>public class MainActivity extends Activity { //private GPUImageView gpuimageview; private Button save_image; private Context mcontext; private ViewPager gallery_pager; private ImagePagerAdapter pageadapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mcontext=MainActivity.this; //gpuimageview=(GPUImageView) findViewById(R.id.gpuimageview); gallery_pager=(ViewPager) findViewById(R.id.view_pager); gallery_pager.setPageMargin(-50); gallery_pager.setHorizontalFadingEdgeEnabled(true); gallery_pager.setFadingEdgeLength(30); pageadapter=new ImagePagerAdapter(mcontext); gallery_pager.setAdapter(pageadapter); gallery_pager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { // TODO Auto-generated method stub } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); } } </code></pre> <p>so can anyone tell me how the thing can be achieve of the first screenshot or i go with the old gallery concept.</p> <p>here the xml part which contain the viewpager</p> <pre><code>&lt;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" tools:context=".MainActivity" &gt; &lt;RelativeLayout android:id="@+id/filtergallery_layout" android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="14dp" android:background="#AA000000" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_height="wrap_content" android:layout_width="wrap_content" /&gt; &lt;/RelativeLayout&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/gpuimageview" android:layout_alignParentLeft="true" android:text="save" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and here is the custom layout which contain the imageview and textview which i m inflating</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/filter_image" android:layout_width="80dp" android:layout_height="80dp" android:src="@drawable/ic_launcher" /&gt; &lt;TextView android:id="@+id/filter_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/filter_image" android:layout_alignParentLeft="true" android:layout_marginLeft="3dp" android:background="#07000000" android:text="filter" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>so any help will be appreciated.Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload