Android Dribble Api 使用

使用Dribble提供的Api获取上面的设计分享

  • 使用了Material Design、SceneTransitionAnimation
  • 使用了Volley Gson

1. 申请Dribble开发者应用

https://dribbble.com/account/applications/new

申请成功之后,就会生成

  • Client ID
  • Client Secret
  • Client Access Token

2. 使用Dribble的Api

还可加page参数获取分页数据

构建类似这样的数据

public class DribbleShot{
    @SerializedName("animated")
    public Boolean mAnimated;
    @SerializedName("attachments_count")
    public Long mAttachmentsCount;
    @SerializedName("attachments_url")
    public String mAttachmentsUrl;
    @SerializedName("buckets_count")
    public Long mBucketsCount;
    @SerializedName("buckets_url")
    public String mBucketsUrl;
    @SerializedName("comments_count")
    public Long mCommentsCount;
    @SerializedName("comments_url")
    public String mCommentsUrl;
}

使用Volley获取数据,Gson解析

private void getData() {
        final String shotUrl = "https://api.dribbble.com/v1/shots?access_token=" + DRIBBLE_Token;
        StringRequest request = new StringRequest(Request.Method.GET, shotUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                Type type = new TypeToken<ArrayList<DribbleShot>>() {
                }.getType();
                dribbleShots = gson.fromJson(response, type);
                //填充到list
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        RequestQueue queue = Volley.newRequestQueue(context);
        queue.add(request);
   }

3. Activity View转场动画

  1. 在跳转的Activity使用ActivityOptionsCompat.makeSceneTransitionAnimation()

    Intent intent = new Intent(context, ShotItemActivity.class);
    ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(context, view, "TRASATION_ANIMATION");
                    ActivityCompat.startActivity(context, itent, optionsCompat.toBundle());
    
    • view 为发生转场动画的控件
  2. 在目标Activity使用ViewCompat.setTransitionName()设定转场动画的接收控件

    ViewCompat.setTransitionName(imageView, "TRASATION_ANIMATION");
    
    • 注意制定的TRANATION_ANIMATION需要保持一致。
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容