I am having a gridView with each item having an image to be loaded. I have used adapter to render the image. I am assigning images as gridView items using resource ID array created using images in drawable folder.
The problem is gridView is being displayed with only 12 images(which fits the view without scrolling). I have around 40 images resource ID in that array. the getView is called only 12-13 times.
Could you pleae help me how to display all 40 images on grid view? Do i need to explicitly add scrollpane in grid.xml?
Below is the grid.xml layout
<?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="fill_parent"
android:orientation="vertical"
android:background="#drawable/wooden_background"
android:id="#+id/RootView">
<GridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:padding="5dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:maxWidth="150dip"
android:maxHeight="150dip" >
</GridView>
</LinearLayout>
Below is the getView function inside adapter
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi;
if (convertView == null){ // if it's not recycled, initialize some attributes
vi = inflater.inflate(R.layout.each_image,parent, false);
}
else{
vi=convertView;
}
/*imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(170,170));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);*/
System.out.println("Inside getView");
ImageView image = (ImageView)vi.findViewById(R.id.imageView);
image.setMaxHeight(150);
image.setMinimumHeight(150);
image.setScaleType(ImageView.ScaleType.FIT_XY );
image.setImageResource(imageIngredientsID[position]);
return vi;
}
How many items the gridview gets depends entirely on your getCount() method in your adapter, what does it return? 12?
Try adding ScrollView to the layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/wooden_background"
android:id="#+id/RootView">
<GridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:padding="5dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:maxWidth="150dip"
android:maxHeight="150dip" >
</GridView>
</LinearLayout>
</ScrollView>
Related
I've created a scaling, evenly-spaced gridview layout for a simple card-matching game I made for my nephew. It's behaving pretty much as I want, but it seems that there should be a less convoluted way to achieve this, so I was wondering if anyone could suggest a better/simpler way. I'm brand new to Android, so it's likely I over-engineered this.
I have a setting to control the # of cards (12-32), and it scales to any size screen (tablet or phone of various sizes and resolutions).
Here's my gridview XML:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#drawable/wood"
android:layout_below="#id/score_board"
android:layout_above="#+id/messageparent"
/>
I have an ImageAdapter subclass of BaseAdapter, with a getView that looks like this. The getCellWidth and getCellHeight functions return a value I set in the main activity on layout change (see below).
public View getView(int position, View convertView, ViewGroup parent) {
CardView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new CardView(mContext,position,mCardFaces[position]); //mThumbIds[position]
imageView.setLayoutParams(new GridView.LayoutParams(((MainActivity)mContext).getCellWidth(), ((MainActivity)mContext).getCellHeight()));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//imageView.setPadding(R.dimen.card_padding, R.dimen.card_padding, R.dimen.card_padding, R.dimen.card_padding);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(CardView.CARDBACK);
} else {
imageView = (CardView) convertView;
//If we recycle an old view, make sure it resizes appropriately
if (imageView.getWidth() != ((MainActivity)mContext).getCellWidth()) {
imageView.setLayoutParams(new GridView.LayoutParams(((MainActivity)mContext).getCellWidth(), ((MainActivity)mContext).getCellHeight()));
}
if(!mCardFaces[position].equals(imageView.getResID()))
imageView.updateCard(mCardFaces[position]);
}
return imageView;
}
Here's the relevant code in my sizeCardsToFit method:
//... algorithm to calc cols, width and height to fit screen
gridview.setNumColumns(nCols);
gridview.setColumnWidth(width);
for (int i = 0; i < gridview.getChildCount(); i++) {
((CardView)gridview.getChildAt(i)).setLayoutParams(new GridView.LayoutParams(width,height));
}
mCellHeight=height;
mCellWidth=width;
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyGrid" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="0dp"
android:verticalSpacing="2dp" android:horizontalSpacing="2dp"
android:scrollingCache="true" android:smoothScrollbar="true"
android:clipChildren="true" android:alwaysDrawnWithCache="true"
android:numColumns="auto_fit" android:columnWidth="100dp"
android:stretchMode="columnWidth" android:gravity="center_horizontal"
android:background="#000000">
</GridView>
thank you for your time.
I have a list of Strings that a display inside a gridview using an ArrayAdapter. Some of those Strings are long and take too much room. I want to limit the height of each grid cell to 1 line and be able to read the full string when i'm clicking on this cell.
Here's my gridview.xml :
<GridView
android:id="#+id/songSelectionGrid_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/songSelectionGrid_button_back"
android:columnWidth="90sp"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:verticalSpacing="10dp" />
and here is my textview inside my gridview :
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:maxLines = "1"
android:scrollbars = "horizontal"/>
How can i make the Strings scroll horizontally ?
I've tried a onItemClickListener on the gridview followed by a "setMovementMethod" on the view, but it need to be a TextView and casting it doesn't seem to work
Thanks !
Ok so I've managed to make it work as intended : gridview displaying multiple albums (cover picture + horizontally scrollable text). To do so, I've created my own GridAdapter with the following getView() :
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView = null;
convertView = null;
if(convertView == null)
{
gridView = new View(context);
gridView = inflater.inflate(R.layout.gridtextview, null);
TextView textView = (TextView) gridView.findViewById(R.id.gridView_text);
textView.setText(textArray[position]);
Log.i("GridAdapter","textView.getText :
}
return gridView;
}
The gridView I am populating is composed of the following :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView_topLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/gridView_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/gridTextView_Album"
android:src="#drawable/ic_launcher" />
<HorizontalScrollView
android:id="#+id/gridView_horizontalScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:clipChildren="true"
android:fillViewport="true"
android:scrollbars="none" >
<RelativeLayout
android:id="#+id/gridView_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/gridView_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:isScrollContainer="true"
android:paddingBottom="10sp"
android:singleLine="true" />
</RelativeLayout>
</HorizontalScrollView>
I am not sure this is the best way of doing it but it does work.
But still, keep in mind I'm still a beginner in android dev :)
I created an app, it's finely working as what i want on minsdkversion="3". But other activities look even bigger than usual. If i change the minsdkversion="8" or something, the other activities looks as normal, but i didn't get the output i want.
Following is the code for gridview and imageview layout files:
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="#+id/grid_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="0dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp"
android:gravity="center_horizontal"
android:clipChildren="true" >
</GridView>
</LinearLayout>
grid.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/image_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.05"/>
</LinearLayout>
MainActivity.java:
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null)
{
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
i = i+1;
imageView.setId(i);
Log.d("===== i value =====", String.valueOf(i));
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
What is the wrong with my code, what i have to change?
I have to show some toast when particular body part is pressed
Step #1: Display the body in an ImageView
Step #2: Override onTouchEvent() in your activity or fragment that is managing the ImageView
Step #3: Determine the body part based on the location of the touch event and the size of the ImageView, and display your Toast
I've got a GridView inside a scrollview and the GridView has 4 images loaded into it (via an ImageAdapter). My issue is I can get 3 of the images to show but the 4th doesn't. After further investigation, I've found that the height of the gridview is only the height of the row, so if I set the gridview height in xml to 700dp, then it shows up.
Here's a screenshot:
As you can see, I've set the background of the GridView to HotPink to illustrate where the GridView is.
Here's the XML for the main_menu:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llLayoutContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- <LinearLayout android:id="#+id/llMiddle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"> -->
<LinearLayout
android:id="#+id/llLeft"
android:layout_width="400dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/layout_left"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<ScrollView
android:id="#+id/svMenu"
android:layout_width="400dp"
android:layout_height="match_parent"
>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/llRight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#drawable/layout_right"
android:padding="0dp">
</LinearLayout>
<!-- </LinearLayout> -->
</LinearLayout>
The LinearLayout "llLeft" is the layout where the menu items get loaded (inside the ScrollView). layout_left is only a shape which draws the dark outline around the greenish background.
Here's the main_menu_header.xml which contains the GridView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="5dp">
<TextView
android:id="#+id/tvDashboardHeader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Dashboard Main Menu"
android:textSize="20dp"
style="#style/TextShadow"
android:paddingTop="5dp"
android:gravity="left"
android:background="#drawable/menu_item_bg"
/>
<GridView
android:id="#+id/gvMenuItems"
android:layout_width="400dp"
android:layout_height="match_parent"
android:columnWidth="110dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:background="#color/HotPink"
android:gravity="center" >
</GridView>
</LinearLayout>
And here's how I populate the GridView:
ScrollView sv = (ScrollView)findViewById(R.id.svMenu);
LayoutInflater liInflater = getLayoutInflater();
ViewGroup vg = (ViewGroup)liInflater.inflate(R.layout.main_menu_header, sv, false);
sv.addView(vg);
//Setup the Main Menu items on the left side.
GridView gvMenuItems = (GridView) findViewById(R.id.gvMenuItems);
gvMenuItems.setAdapter(new ImageAdapter(this));
ImageAdapter class:
ImageAdapter class:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(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(parent.getLayoutParams().width, 125)); //new GridView.LayoutParams(400, 125));
//imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setMaxHeight(50);
imageView.setMaxWidth(50);
//imageView.setPadding(30, 0, 0, 0);
//imageView.setPadding(40, 30, 20, 30);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.home,
R.drawable.open_folder,
R.drawable.paper_pen,
R.drawable.person
};
}
I thought the gridview property of android:layout_height="match_parent" would work but it's not. Any ideas as to how I can get the GridView to take up the whole left side, inside the scrollview?
My best guess is that scrollview is giving you problem.
Why do u need scrollview for?
Grid View will handle the scrolling. It is kind of redundant.So please remove it and add inflated view directly to llLeft directly. That shall solve the problem.
In fact, it would be more elegant just to use xml to solve your UI problem. Use <include> tag in your main_menu.xml. Here is how
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llLayoutContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- <LinearLayout android:id="#+id/llMiddle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"> -->
<LinearLayout
android:id="#+id/llLeft"
android:layout_width="400dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/layout_left"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/main_menu_header" />
</LinearLayout>
<LinearLayout
android:id="#+id/llRight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#drawable/layout_right"
android:padding="0dp">
</LinearLayout>
<!-- </LinearLayout> -->
See below layout. I am unable to put footer button below a GridView.
Any help will be appreciate.
When Gridview fill in the screen Button is not displayed.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/gridview"
android:text="Load More Images" />
</RelativeLayout>
I have been keeping searching for a long time for a GridView which allows us to addFooterView and addHeaderView like ListView.
It's a post 2 years ago. I come here by following the link in google search result. I don't know weather this problem has been solved or not.
If not, here is a library which may be helpful. https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter.
It's very simple:
GridViewWithHeaderAndFooter gridView = (GridViewWithHeaderAndFooter) v.findViewById(R.id.ly_image_list_grid);
LayoutInflater layoutInflater = LayoutInflater.from(this);
View headerView = layoutInflater.inflate(R.layout.test_header_view, null);
View footerView = layoutInflater.inflate(R.layout.test_footer_view, null);
gridView.addHeaderView(headerView);
gridView.addFooterView(footerView);
Here is a screen snapshot:
Hope this would be helpful. Good luck!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<GridView android:layout_height="match_parent" android:id="#+id/all_workouts_list"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" android:cacheColorHint="#ffffffff"
android:layout_width="match_parent"
android:layout_above="#+id/add_workout_all_workout_list"></GridView>
<Button android:layout_width="wrap_content"
android:id="#+id/add_workout_all_workout_list" android:layout_height="wrap_content"
android:text="Add Workout" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
Works fine for me
I managed to add footer to my gridview with a little trick. Lets say your adapters main data is
List of MyDataInfo objects list, now when you passed all the data to adapter you can add two empty(null)
objects and check in getView whether data is null or not and inflate desired view .
// in the adapter
public void addVoid(YourInfo info) {
dataList.add(info);
dataList.add(info);
notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
if (dataList.get(position) !=null) {
View vi = convertView;
ViewHolder holder;
if (convertView == null || convertView.getTag().equals("stop")) {
//inflate your gridview item
}
else {
holder = (ViewHolder) vi.getTag();
}
// provide data to views
return vi;
}
else {
View v;
if (position == dataList.size() - 2) {
v = inflater.inflate(R.layout.show_more, null); // load more view
v.setTag("stop");
}
else {
v = inflater.inflate(R.layout.progress_bar, null); // progress bar
v.setTag("stop");
}
return v;
}
}
Before this in your main activity where you set adapter you'll have something like this
YourAdapter adap = new YourAdapter(this, dataList);
gridView.setAdapter(adap);
YourInfo info = null;
adapter.addVoid(info);
And important thing you'll have to handle onitemclick
int size = adapter.getCount();
public void onItemClick(AdapterView<?> parent,View view, int position, long id) {
if (position == size - 2) { // user selected SHOW MORE view
int wantedPosition = size - 1;
int firstPosition = grid.getFirstVisiblePosition();
int wantedChild = wantedPosition- firstPosition;
ProgressBar progBar = grid.getChildAt(wantedChild);
progBar.setVisibility(View.Visible);
return;
}
if (position == size - 1) // user selected progress bar
return;
}
Hope this helps ^^
Add to GridView two attributes:
android:paddingBottom of the size as your Button;
android:clipToPadding="false"
This will make some space for button at the bottom of the grid.
Use the same as the below:
Edited:
<FrameLayout android:id="#+id/linear_Layout_List"
android:layout_gravity="center_horizontal|top|bottom"
android:layout_marginTop="90dip" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginBottom="60dip" android:background="#E4E4E4">
<GridView android:layout_width="fill_parent"
android:layout_gravity="center_horizontal|top|bottom"
android:columnWidth="90dp" android:numColumns="3"
android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
android:gravity="center" android:id="#+id/Search_Result_Grid"
android:background="#E4E4E4" android:focusable="true"
android:verticalSpacing="10dp" android:layout_height="wrap_content"
android:layout_marginBottom="45dip">
</GridView>
<Button android:id="#+id/txt_LoadMoreGrid"
android:layout_width="fill_parent" android:layout_gravity="center_horizontal|bottom"
android:layout_height="wrap_content" android:text="Load More...."
android:clickable="true" android:textColor="#ffffff"
android:visibility="invisible" android:background="#drawable/top_bar_bg"></Button>
</FrameLayout>
and Call the onScroll method to hide the same as you want...........this implementation for LOAD MORE functionality in GridView.............It works for me.
grid.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
System.out.println("The first visible Item:"+firstVisibleItem);
if(width<=320 && height<=480)
{
if(firstVisibleItem+5==totalItemCount-1)
{
/*FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.NO_GRAVITY);
layoutParams.setMargins(0, 0, 0, 45);
grid.setLayoutParams(layoutParams);*/
tv_Load.setVisibility(tv_Load.VISIBLE);
}
else
{
/* FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.NO_GRAVITY);
layoutParams.setMargins(0, 0, 0, 0);
grid.setLayoutParams(layoutParams);*/
tv_Load.setVisibility(tv_Load.GONE);
}
}
else
{
if(firstVisibleItem+8==totalItemCount-1)
{
/*FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.NO_GRAVITY);
layoutParams.setMargins(0, 0, 0, 45);
grid.setLayoutParams(layoutParams);*/
tv_Load.setVisibility(tv_Load.VISIBLE);
}
else
{
/* FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.NO_GRAVITY);
layoutParams.setMargins(0, 0, 0, 0);
grid.setLayoutParams(layoutParams);*/
tv_Load.setVisibility(tv_Load.GONE);
}
}
}
});
Try adding the button first and putting the grid view on top of it. Something like this ought to work:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Load More Images" />
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/button1"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</RelativeLayout>
EDIT
Based on your comments, I can see why the above does not work. Assuming you mean that you want the button to appear only after you scroll to the bottom (and not be on the screen the entire time), here's the layout I recommend:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More Images" />
</LinearLayout>
</ScrollView>
check if this helps
<Button
android:id="#+id/button1"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Load More Images" />