【问题标题】:Pinterest like custom GridViewPinterest 喜欢自定义 GridView
【发布时间】:2016-05-04 04:53:11
【问题描述】:

我是 android 新手,我正在寻找网格视图的逻辑,例如为 i-phone 构建的 pinterest(homescreen) 应用程序。一个大号。图片来自服务器,我需要以带有分页效果的以下形式显示,即在滚动时加载图像。

如果有可能,请回复。我将非常感谢。

【问题讨论】:

  • 我正在努力使网格视图适应 iPhone 应用程序上 pinterest 使用的布局。您是否曾经能够使用网格布局或任何其他布局方案在 iPhone 上创建类似于 pinterest 布局的东西?
  • 你好@Raj Kumar Yadav。你能帮我做同样的事吗?你在 android 中得到了相同图像的输出吗?

标签: android


【解决方案1】:

如果您想在滚动时执行图像加载,则它类似于列表视图。首先保存 WS URL 中的所有数据,然后立即按需加载

Commonsware Endless Adapter For Listview,也可以和GridView集成

EndLessAdapter

另一种方法是将网格视图放在ViewFlipper 中,然后用动画翻转。

使用 setInAnimation() 和 setOutAnimation() 设置动画并使用 showNext() 和 showPrevious() 进行翻页

【讨论】:

    【解决方案2】:

    如下创建布局

    <ScrollView...>
    <LinearLayout....
       android:id="@+id/linear1"
       orientation="horizontal">
    
       <LinearLayout....
         android:id="@+id/linear2"
         android:layout_weight="0.33"
         orientation="vertical">
    
       <LinearLayout....
         android:id="@+id/linear3"
         android:layout_weight="0.33"
         orientation="vertical">
    
       <LinearLayout....
         android:layout_weight="0.33"
         orientation="vertical">
    
    </LinearLayout>
    </ScrollView>
    

    现在在布局中动态添加您的 ImageView

    linear1 = (LinearLayout) findViewById(R.id.linear1);
    linear2 = (LinearLayout) findViewById(R.id.linear2);
    linear3 = (LinearLayout) findViewById(R.id.linear3);
    
    for(int i=0;i<n;i++)
    {
       ImageView iv = new ImageView(this);
       iv.setImageResource(R.id.icon);
    
       int j = count % 3;  <---- 
       if(j==0)
           linear1.addView(iv);
       else if(j==1)
           linear2.addView(iv);
       else
           linear3.addView(iv); 
    }
    

    【讨论】:

      【解决方案3】:

      检查:Staggered GridView

      StaggeredGridView 允许用户创建具有不均匀行的 GridView,类似于 Pinterest 的外观。包括自己的 OnItemClickListener 和 OnItemLongClickListener、选择器和固定位置恢复。

      【讨论】:

        【解决方案4】:

        这是一个老问题,但对于那些有类似问题的人:

        实现这种布局风格最简单的方法是使用带有 StaggeredGridLayoutManager 的 RecyclerView,像这样:

         protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_activity);
        
            View recyclerView = findViewById(R.id.recycle_view);
            assert recyclerView != null;
            StaggeredGridLayoutManager gaggeredGridLayoutManager = new      
            StaggeredGridLayoutManager(2, 1);
                recyclerView.setLayoutManager(gaggeredGridLayoutManager);
        }
        

        对于问题的另一部分(分页),最好以块的形式接收您的图像(例如,每个请求 50 个图像),并且当用户向下滚动(到达结尾)时加载更多。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-02
          • 1970-01-01
          相关资源
          最近更新 更多