StatefulLayout, 用于显示加载,空,错误等模板的Android布局 状态

分享于 

4分钟阅读

GitHub

  繁體 雙語
Android layout to show template for loading, empty, error etc. states
  • 源代码名称:StatefulLayout
  • 源代码网址:http://www.github.com/gturedi/StatefulLayout
  • StatefulLayout源代码文档
  • StatefulLayout源代码下载
  • Git URL:
    git://www.github.com/gturedi/StatefulLayout.git
    Git Clone代码到本地:
    git clone http://www.github.com/gturedi/StatefulLayout
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/gturedi/StatefulLayout
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    StatefulLayout

    Android ArsenalAPIMavenCentralBuild StatusLicense

    Android布局显示最常用的状态模板,比如加载。空。错误 等等 这样做,你需要将目标 area(view) 封装为 StatefulLayout。

    alt text

    用法

    将dependecy添加到 app/build。gradle

    dependencies {
     compile 'com.github.gturedi:stateful-layout:1.2.1'}

    开发版本的快照在sonatype存储库的snapshots 可用。

    然后包装目标 area(view)的视图,以StatefulLayout显示状态

     <com.gturedi.views.StatefulLayout
     android:id="@+id/stateful"android:layout_width="match_parent"android:layout_height="match_parent"app:stfAnimationEnabled="true"app:stfInAnimation="@android:anim/slide_in_left"app:stfOutAnimation="@android:anim/slide_out_right"> 
     <!-- your content here --> <LinearLayoutandroid:id="@+id/target"android:layout_width="wrap_content"android:layout_height="wrap_content"> 
    . . .
     </LinearLayout>
     </com.gturedi.views.StatefulLayout>

    最后在 Activity/fragment 中获取StatefulLayout引用并调用showXXX方法

    StatefulLayout stateful = (StatefulLayout) findViewById(R.id.stateful);
    stateful.showLoading();//stateful.showEmpty(getString(R.string.testMessage));//stateful.showError(getString(R.string.testMessage), clickListener);//etc.

    API

    状态方法具有自定义的重载。 如果将clickListener参数作为null传递,相关状态按钮将被隐藏。 更多定制请看 CustomStateOptions.java

    • setAnimationEnabled ( 布尔 animationEnabled )
    • setInAnimation ( @AnimRes int inAnimation )
    • setOutAnimation ( @AnimRes int outAnimation )
    • showContent ( )
    • showLoading ( 字符串消息)
    • showEmpty ( 字符串消息)
    • showError ( 字符串消息,OnClickListener clickListener )
    • showOffline ( 字符串消息,OnClickListener clickListener )
    • showLocationOff ( 字符串消息,OnClickListener clickListener )
    • showCustom ( CustomStateOptions选项)

    Xml属性

    名称类型默认说明
    stfAnimationEnabled布尔型true指示是否将动画放置在状态更改上
    stfInAnimation动画@android:anim/fade_in状态更改开始时的动画开始
    stfOutAnimation动画@android:anim/fade_out动画开始状态更改结束

    文档级自定义项

    仅覆盖应用程序中的相关资源以自定义状态视图外观

    许可证

    
    Copyright 2017 Gökhan Türedi (turedi.gokhan@gmail.com)
    
    
    
    Licensed under the Apache License, Version 2.0 (the"License");
    
    
    you may not use this file except in compliance with the License.
    
    
    You may obtain a copy of the License at
    
    
    
     http://www.apache.org/licenses/LICENSE-2.0
    
    
    
    Unless required by applicable law or agreed to in writing, software
    
    
    distributed under the License is distributed on an"AS IS" BASIS,
    
    
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    
    
    See the License for the specific language governing permissions and
    
    
    limitations under the License.
    
    
    
    

    STA  TEMP  STAT  template  显示  Layout  
    相关文章