在同一个活动二GridView的之间切换 [英] Switching between two GridViews in the same Activity

查看:222
本文介绍了在同一个活动二GridView的之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找着如何解决几个问题,得到了几个答案我的一些问题,但有一点是仍在建设中,将无法完成,如果没有,你可以帮助我。 :/

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. :/

我一直在试图放大和缩小的GridView的,但得到了一个其他的解决方案,因为我只需要两种状态:概述和详细视图。为此,我做了两个GridView的。第一个是一个,其中两个GridView中的图像缩小,显示无需滚动。另一种是,其中的图像显示在他们的原始尺寸之一。你可以一个内部的水平和垂直滚动。

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.

我的问题是这两个GridView的之间的切换。我试着两者的知名度设置要么水涨船高或可见如果我在其中一人点击。

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.

下面是我的code:

启动:

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:

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:

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>

你对如何这两个GridView控件之间进行切换,我有什么建议?让我知道:)

Do you have any suggestions for me on how to switch between those two gridview? Let me know :)

巴斯蒂

推荐答案

恕我直言,你可以真的很好实施的 ViewFlipper 您2网格之间切换!搜索结果
在Android的参考指南

Imho you could really nicely implement a ViewFlipper to switch between your 2 Grids!

From android reference guide:

ViewFlipper是一个简单的ViewAnimator,将动画
  具有两个或多个视图之间
  被添加到它。只有一个孩子
  一次显示。如果需要,可以
  每个孩子之间自动翻转
  在固定时间间隔。

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.

下面是一个例子就如何实现这一的。结果
这里是<一个href=\"http://www.warriorpoint.com/blog/2009/05/26/android-switching-screens-in-an-activity-with-animations-using-viewflipper/\"相对=nofollow>另一个例子演示此(动画)

Here is an example on how to implement this.
Here is another example that demonstrates this ( with animation )

这篇关于在同一个活动二GridView的之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆