Switching between two GridViews in the same Activity - android

I've been looking around how to solve several problems and got several answers to some of my question, but one thing is still under construction and won't be finished if none of you can help me. :/
I've been trying to zoom in and out of a GridView, but got over to an other solution, since I do only need two states: an overview and a detailed view. Therefor I've made two Gridviews. The first one is the one where the images inside both gridviews are shrunk and displayed without scrolling. The other one is the one where the images are displayed in their original size. You can scroll horizontally and vertically inside that one.
My problem is the switching between those two gridviews. I've tried to "set the visibility" of both to either "gone" or "visible" if i clicked on one of them.
Here's my code:
Starter:
package test.scroll;
import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.view.View;
import android.view.View.OnClickListener;
public class TestScrollActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final GridView grd_overview = (GridView)this.findViewById(R.id.grd_overview);
grd_overview.setAdapter(new OverviewImageAdapter(this));
final GridView grd_detailed = (GridView)this.findViewById(R.id.grd_detailed);
grd_detailed.setVisibility(2);
grd_detailed.setAdapter(new DetailedImageAdapter(this));
grd_overview.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
grd_overview.setVisibility(2);
grd_detailed.setVisibility(0);
}
});
grd_detailed.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
grd_detailed.setVisibility(2);
grd_overview.setVisibility(0);
}
});
}
}
OverviewAdapter:
package test.scroll;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class OverviewImageAdapter extends BaseAdapter {
private Context mContext;
public OverviewImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(82, 82));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,
R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,
R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,
R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,
R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,
R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1
};
}
DetailedAdapter:
package test.scroll;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class DetailedImageAdapter extends BaseAdapter {
private Context mContext;
public DetailedImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(82, 82));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,
R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,
R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,
R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,
R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,
R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2
};
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- PLAYGROUND -->
<test.scroll.TwoDScrollView
android:id="#+id/scene_scroller"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/grds"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<GridView
android:id="#+id/grd_overview"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:id="#+id/grd_detailed"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</test.scroll.TwoDScrollView>
<!-- ATTRIBUTES -->
<Button
android:id="#+id/btn_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scene_scroller"
android:text="cancel"
/>
</RelativeLayout>
Do you have any suggestions for me on how to switch between those two gridview? Let me know :)
Basti

Imho you could really nicely implement a ViewFlipper to switch between your 2 Grids!
From android reference guide:
ViewFlipper is a simple ViewAnimator that will animate
between two or more views that have
been added to it. Only one child is
shown at a time. If requested, can
automatically flip between each child
at a regular interval.
Here is an example on how to implement this.
Here is another example that demonstrates this ( with animation )

Why not just place both GridViews within a ViewSwitcher/ViewFlipper, and just flip between them that way?

You should be able to remove the grid you don't wanna see, from app_layout and add the one you want to see. Example:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.app_layout);
GridView gv = (GridView) findViewById(R.id.grid01); // Replace the ID
GridView gv2 = (GridView) findViewById(R.id.grid02); // Replace too
//...
rl.removeView(gv);
rl.addView(gv2);
// ...
rl.removeView(gv2);
rl.addView(gv);
And so on.

Related

ImageButton inside of GridView not clickable

Here is my code for dynamically creating ImageButtons inside of gridviews. When I run the activity, the ImageButtons are not clickable. I tried adding
android:descendantFocusability="blocksDescendants"
to the xml file but this did not fix the problem.
EDIT: I updated the adapter to be for ImageViews, not ImageButtons, but the problem persists.
Here is my custom adapter:
package com.example.myname.myproject;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
/**
* Created by myname on 3/31/17.
*/
public class ImageArrayAdapter extends BaseAdapter {
Context context;
int[] currentResources;
String[] currentIcons;
public ImageArrayAdapter(Context context, String[] currentIcons, int[] currentResources){
ImageArrayAdapter.this.context = context;
ImageArrayAdapter.this.currentIcons = currentIcons;
ImageArrayAdapter.this.currentResources = currentResources;
}
#Override
public int getCount() {
return currentResources.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setBackgroundColor(Color.TRANSPARENT);
} else {
imageView = (ImageView) convertView;
}
imageView.setClickable(true);
imageView.setImageResource(currentResources[position]);
return imageView;
}
}
Here is my xml file for the GridView.
<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="com.example.myname.myproject.AdminControlTabbed$PlaceholderFragment">
<GridView
android:id="#+id/templateGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
/>
Thanks for the help.
Why not ImageViews instead of ImageButtons. Then you have to only set an OnItemClickListener for your GridView in the activity class where you have initialized it. After you attach the adapter to it, you can attach a clickListener too like this:
myGridView.setAdapter(this, currentIconsArray, currentResourcesArray);
myGridViewsetOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//code for handling onClick event
}
});
Activity.dispatchTouchEvent(MotionEvent) dispach it to other listeners

Move text below application icon in GridView

Hello Guys How can arrange appname under the icon ? If you need i give the source.
You can see the code used to create this view here:
package com.example.draw;
import java.util.List;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class AppInfoAdapter extends BaseAdapter {
private Context mContext;
private List<ApplicationInfo> mListAppInfo;
private PackageManager mPackManager;
public AppInfoAdapter(Context c, List<ApplicationInfo> list, PackageManager pm) {
mContext = c;
mListAppInfo = list;
mPackManager = pm;
}
#Override
public int getCount() {
return mListAppInfo.size();
}
#Override
public Object getItem(int position) {
return mListAppInfo.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// get the selected entry
ApplicationInfo entry = mListAppInfo.get(position);
// reference to convertView
View v = convertView;
// inflate new layout if null
if(v == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.activity_appinfo, null);
}
// load controls from layout resources
ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);
// set data to display
ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
// return view
return v;
}
}
Text come from
TextView tvAppName = (TextView)v.findViewById(R.id.tvName);
tvAppName.setText(entry.loadLabel(mPackManager));
main_appinfo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="center"
android:gravity="center_horizontal|center_vertical"/>
</LinearLayout>
The LinearLayout in layout file horizontal, make it vertical.
android:orientation="horizontal" to android:orientation="vertical"
App Icon and title format is part of the Home Screen App in android, you can't modify its look.
If you want you can create your own Home Screen App and do whatever you want with it.
Here is an example for home screen apps : Home App Android sdk Sample

android gallery textview horizontal list rounded edges

I'm implementing horizontal scrolling textview list something like an ebook with thumbing pages. I take the Gallery widget dispaying TextViews. The first problem I faced is that the left and right edges of each page look rounded.
Here is the sample code:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:spacing="0px"/>
</LinearLayout>
page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery_item"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"/>
</LinearLayout>
GalleryActivity.java
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.TextView;
public class GalleryActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new GalleryAdapter(this));
}
private class GalleryAdapter extends BaseAdapter {
private Context context; // needed to create the view
public GalleryAdapter(Context c) {
context = c;
}
public int getCount() {
return 5;
}
public Object getItem(int position) {
return position; //TODO: get the object on the position
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView == null)
v = LayoutInflater.from(context).inflate(R.layout.page, parent, false);
else
v = convertView;
TextView tv = (TextView) v.findViewById(R.id.textView);
tv.setText("Page" + position);
return v;
}
}
}
Any Idea how to get page edges like on the e.g. titlebar? Maybe another way to achive the goal?
in page.xml instead of givin match_parent give a fxd width for layout and give sm padding for txtview.
And FYI Gallery is deprecated, use view pager instead.
The View pager comes with the compatibility package too:http://developer.android.com/tools/extras/support-library.html
and if u can't give a fxd width then u can only try with padding ,this might sove ur prblm

Display blank item in grid view

On home scree of application, how to display the menu which is similar to android menu but no items needs to be displayed in specific cells. Considering grid of 3 x 3, five items only needs to be displayed at (Row, Col): [0,1], [1,0], [1,1], [1,2], [2,1].
We have tried GridView and set visibility to GONE (convertView.setVisibility(View.GONE);) for items which need not be displayed. Following this, item is not displayed in grid but when user browses through blank item using up and down keys or click directly on blank item, that icon is hihglighted and selected as if it is blank item in grid. We want as it is blank it should not repond to user events neither highlighted not selected.
Code for Grid View:
package org.XXX;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class XXXActivity extends Activity {
GridView MyGrid;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.maingrid);
MyGrid = (GridView)findViewById(R.id.MyGrid);
MyGrid.setAdapter(new ImageAdapter(this));
MyGrid.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Toast.makeText(arg0.getContext(), position + " selected", Toast.LENGTH_LONG).show();
switch(position) {
case 0:break;
case 1:
//Browse
Intent newIntent = new Intent(XXXActivity.this, YYYListItemIcons.class);
startActivity(newIntent);
break;
case 2:break;
case 3:
//Saved Searches
newIntent = new Intent(XXXActivity.this, ZZZListItemIcons.class);
startActivity(newIntent);
break;
case 4:
//Sign in
break;
case 5:
//Reminders
break;
case 6:break;
case 7:
//Sign up
break;
case 8:break;
}
}
});
//onSearchRequested(); //to open search by default
}
public class ImageAdapter extends BaseAdapter
{
Context MyContext;
public ImageAdapter(Context _MyContext)
{
MyContext = _MyContext;
}
#Override
public int getCount()
{
return 9;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater mInflater = LayoutInflater.from(MyContext);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.grid_item, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.grid_item_text);
holder.icon = (ImageView) convertView.findViewById(R.id.grid_item_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.text.setText(getTextId(position));
holder.icon.setImageBitmap(BitmapFactory.decodeResource(MyContext.getResources(), getIconId(position)));
if(getIconId(position) == R.drawable.nothing) {
convertView.setVisibility(View.GONE);
}
return convertView;
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
private int getIconId(int position) {
int iconImages[] = {
R.drawable.nothing,
R.drawable.browse,
R.drawable.nothing,
R.drawable.saved_searches,
R.drawable.sign_in,
R.drawable.reminders,
R.drawable.nothing,
R.drawable.sign_up,
R.drawable.nothing
};
return iconImages[position];
}
private int getTextId(int position) {
int iconNames[] = {
R.string.nothing,
R.string.browse,
R.string.nothing,
R.string.saved_searches,
R.string.sign_in,
R.string.reminders,
R.string.nothing,
R.string.sign_up,
R.string.nothing
};
return iconNames[position];
}
}
static class ViewHolder {
TextView text;
ImageView icon;
}
}
GridLayout:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="20dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center">
</GridView>
PerItemIconLayout in Grid:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/GridItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView android:id="#+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView android:id="#+id/grid_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#FFFFFF">
</TextView>
</LinearLayout>
if(getIconId(position) == R.drawable.nothing) {
convertView.setVisibility(View.GONE);
}
replace the above lines by below and try....
if(getIconId(position) == R.drawable.nothing) {
convertView.setVisibility(View.GONE);
convertView.setClickable(false);
convertView.setEnabled(false);
}
try this code in getview().
Now that you have posted your code, I am not sure if you can technically remove but you can disable the "highlighted" click that you are talking about, this way, when a user clicks on the one of the icons, it will no longer highlight.
This can be done via XML or in your code:
https://stackoverflow.com/questions/2865683/android-disable-highlighting-in-gridview
Code: GridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
XML: android:listSelector="#00000000"
However, this will affect all the icons in your gridview.
Also take a look at this:
https://stackoverflow.com/questions/5514629/how-to-disable-item-click-for-particular-positions-in-grid-view-in-android

Android GalleryView Problem

I have a problem with android galleryview, in my app I have a lot of pictures. And I wanna display them by gallerview and make them selectable. I figured out displaying them horizontal scrollable and make them selectable with Galleryview, but I need one image on the screen at a time, after horizontal scrolling the scrollbar by the user, another picture must be shown. My test code is below and this shows 3 pictures on the screen, from http://www.androidpeople.com/android-gallery-example:
package com.projects.cards;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
public class GaleryTestActivity extends Activity {
private Gallery gallery;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.galery);
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// Displaying the position when the gallery item in clicked
Toast.makeText(GaleryTestActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
// Adding images.
private Integer[] Imgid = {
R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
};
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
imgView.setImageResource(Imgid[position]);
// Fixing width & height for image to display
imgView.setLayoutParams(new Gallery.LayoutParams(200, 160));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
return imgView;
}
}
}
How can I solve this problem?
Thanks in advance..
As I understand it, you want the currently focused image to take up all the screen space. You can achieve this by setting the width of the ImageView where you bind it to the Gallery (in getView). Try setting the width of the image to match the width of the device screen.
Note that you can also set the spacing between the items in the Gallery with the gallery.setSpacing(...) method.
I can not tell you how to show a scrollbar, sorry.
I have implemented gallery view like, one that is mentioned in the below in the link. Please try that also: Android gallery with caption
You can try returning view with fill parent as its width which contains your imageview from your adapters getView() ...
Or alse you can do something like this
getview function
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater iteminflater = LayoutInflater.from(cont);
View gallaryitem = iteminflater .inflate(R.layout.gallaryitem, null);
ImageView imgView= (ImageView ) gallaryitem .findViewById(R.id.image);
imgView.setImageResource(Imgid[position]);
gallaryitem .setBackgroundResource(GalItemBg);
return gallaryitem ;
}
gallaryitem.xml
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView android:layout_width="wrap_content"
android:id="#+id/image"
android:layout_height="wrap_content"
android:src="#drawable/icon"
xmlns:android="http://schemas.android.com/apk/res/android" >
</ImageView>
</LinearLayout>
</LinearLayout>

Categories

Resources