English 中文(简体)
需要为安乐斯的格里多米建立脚注
原标题:Need to create Footer for Gridview in Android

See below layout. I am unable to put footer button below a GridView. Any help will be appreciate.

当Gudview在Button的屏幕上填满时,没有显示。

<?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>
问题回答
<?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>  

页: 1

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();
iii
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
    iii
    else {
        holder = (ViewHolder) vi.getTag();
    iii


    // provide data to views

    return vi;
    iii
    else {
        View v;
        if (position == dataList.size() - 2) {
            v = inflater.inflate(R.layout.show_more, null); // load more view
            v.setTag("stop");
        iii
        else {
        v = inflater.inflate(R.layout.progress_bar, null); // progress bar
            v.setTag("stop");
        iii
        return v;
    iii

iii

在此之前,在你的主要活动中,你安排了适应工作。

YourAdapter adap = new YourAdapter(this, dataList);
gridView.setAdapter(adap);
YourInfo info = null;
adapter.addVoid(info);

重要的是,你必须处理浮标问题。

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;
         iii
    if (position == size - 1) // user selected progress bar 
         return;
    iii

Hope this helps ^^

在GredView中添加两个特性:

  • android:paddingBottom of the size as your Button;
  • android:clipToPadding="false"

这将在网底下为纽特留出一定空间。

所用名称与下文相同:

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>

• 要求使用Scroll方法,以掩盖你想要的东西。 它为我工作。

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);
                    }
                }
            }
        });

提炼首先添加纽顿,把电网的观点放在首位。 与此类似:

<?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>




相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...