美文网首页
关于知乎新闻案例的模仿

关于知乎新闻案例的模仿

作者: MalDev | 来源:发表于2016-11-30 09:52 被阅读0次

1.ToolBar

参看该文章http://www.jianshu.com/p/79604c3ddcae
项目参看: SystemUITest

2.RecyclerView

http://www.jianshu.com/p/f592f3715ae2

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

    <com.example.systemuitest.AttrsTypedArray.CustomView
       //放在这个地方没有问题
        xmlns:xyz="http://schemas.android.com/apk/res/com.example.systemuitest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xyz:text="hello"
        xyz:textAttr="29"
        />

</LinearLayout>

关于命名空间参考:http://blog.csdn.net/janice0529/article/details/34425549

TypedArray是(存放attrs列出的属性值)方便直接取出

public class CustomView extends View {
    private static final String TAG=CustomView.class.getSimpleName();
    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        //Return a TypedArray holding the attribute values in set that are listed in attrs.
        //返回一个TypedArray(存放attrs列出的属性值)
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.test);
        String text = ta.getString(R.styleable.test_text);//别忘了是放在styleable之下的
        int textAttr = ta.getInteger(R.styleable.test_textAttr, -1);
        Log.e(TAG, text+"----"+textAttr );

        ta.recycle();
    }
}

关于第一篇博文中用数组存储attr的属性值,并用TypedArray通过下标获取对应的属性值
会出现一个bug:

Error: Expected resource of type styleable

解决方法如下:在使用 TypedArray 的方法处
加上 @SuppressWarnings("ResourceType")

 @SuppressWarnings("ResourceType")

案例代码

//在这儿加的
@SuppressWarnings("ResourceType")
public class CustomVewActivity extends View {
    private static final String TAG = CustomVewActivity.class.getSimpleName();
    private static final int[] mAttrs = {R.attr.test3, R.attr.test4};

    public CustomVewActivity(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray ta = context.obtainStyledAttributes(attrs, mAttrs);
        String test3 = ta.getString(0);
        int test4 = ta.getInteger(1, -1);

        Log.e(TAG, test3+"--"+test4 );
        ta.recycle();
    }
}


getItemOffsets():从字面意思就是Item要偏移, 由于我们在Item和Item之间加入了分隔线,线其实本质就是一个长方形,也是用户自定义的,既然线也有长宽高,就画横线来说,上面的Item加入了分隔线,那下面的Item就要往下平移,平移的量就是分隔线的高度。

  • 关于分割线后续实际代码

上面两篇已经讲得很清楚了,原理就是第一篇博文写的那样,很清晰明白,需要注意的问题是在列表方向是垂直的时候(一般为默认),需要画水平线,第一篇博文思路很清晰,问题在于列表方向是垂直的时候,item应该向下平移

3. DrawingCache

缓存视图.png

关于这段代码其中用到DrawingCache,官网API解释:

void setDrawingCacheEnabled (boolean enabled)

Enables or disables the drawing cache. When the drawing cache is enabled, the next call to getDrawingCache() or buildDrawingCache() will draw the view in a bitmap. Calling [draw(android.graphics.Canvas)]
will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling getDrawingCache()
and draw it on screen if the returned bitmap is not null.

关于参数:
boolean enabled: true to enable the drawing cache, false otherwise

http://1137907860.blog.51cto.com/10452906/1682078中说到

若想更新cache, 必须要调用destoryDrawingCache方法把旧的cache销毁,才能建立新的。
>当调用setDrawingCacheEnabled方法设置为false, 系统也会自动把原来的cache销毁。

对比看
http://souly.cn/%E6%8A%80%E6%9C%AF%E5%8D%9A%E6%96%87/2016/01/05/DrawingCache%E8%A7%A3%E6%9E%90/

有点不同暂时先记录吧

4.ObjectAnimation

关于这部分之前已经接触过而且比较简单,只是实现一下动画的类型直接参看下面一篇文章即可
http://blog.csdn.net/dingfengnupt88/article/details/51556597

透明度(alpha)

透明度.png

代码实现如上:该示例代码并没有在onAnimationEnd中实现相应函数

5.ViewStub

参看
http://souly.cn/%E6%8A%80%E6%9C%AF%E5%8D%9A%E6%96%87/2015/09/18/ViewStub%E7%94%A8%E6%B3%95%E5%88%86%E6%9E%90/

1.用途:
最大的用途就是实现View的延迟加载,在需要使用的时候再加载view
在这个项目中作者是用来显示网络通知的(平时不需要显示,在无网络时使view可见)
2.特点
ViewStub inflate之后就会变成空的(所以点击第一次按钮textView会显示出来,第二次点击会报空指针异常 最好加一个非空判断

StubActivity实现.png

相关文章

  • 关于知乎新闻案例的模仿

    1.ToolBar 参看该文章http://www.jianshu.com/p/79604c3ddcae项目参看:...

  • 老外眼中的中国,有点让人啼笑皆非

    Quora作为知乎模仿抄袭的对象,应该是知乎的鼻祖了,其实说国际版知乎,有点抬高身价的嫌疑了。知乎在国内,特别是知...

  • 知乎变现[案例]

    知乎的权重真的非常高,大家可以在百度上搜索一下关键词“降噪耳机”,首页除了上面3个竞价推广,第4个就是知乎的好物测...

  • 【知乎运营攻略】你知道知乎运营的正确打开方式吗?

    最近看了好多关于知乎运营的文章与案例,学到了很多有关知乎运营的知识。比较赞同是名为老A和悟空的运营方法,不赞同的是...

  • 虢雪《爆文制造》读书笔记三

    素材使用的1234原则: 1(生活化的故事素材一则)+2(影视综艺案例一则+新闻热点案例一则)+3(知乎高赞问答、...

  • 关于知乎

    我在简书开账号的同时,也在知乎开了账号~ 我最近怀疑自己在简书、知乎开写作分享账号的真实动机了~

  • 有问题先知乎

    知乎是我当前访问最频繁的网站。知乎逐渐走向大众,身边也有越来越多的人访问知乎。 到知乎看新闻。自从有了知乎,网易新...

  • 模仿你自己

    模仿你自己,奇怪吗?是的。 前几天刚看一条新闻,关于模仿明星的新闻,模仿得再像也只是像,模仿是一种艺术,它对于一个...

  • 模仿知乎日报(RxJava、MVP)

    RX_ZhiHu是模仿知乎日报,基于MVP架构的、遵循Material Design设计规范的APP。接触安卓也快...

  • 5 个维度比较:知乎和简书到底存在哪些差异?

    知乎和简书,好像有点类似:比如,在很多产品细节上,简书都有模仿知乎的痕迹;比如,知乎作者和简书作者的变现模式如初一...

网友评论

      本文标题:关于知乎新闻案例的模仿

      本文链接:https://www.haomeiwen.com/subject/pnwzpttx.html