eclipse中使用scrollingActivity的过程
来源:互联网 发布:611资源网新域名贴吧 编辑:程序博客网 时间:2024/05/16 18:31
scrollingActivity是android studio中可以直接创建的activity炫酷的详情页,属于support-design
网上的动态效果图
1.引入过程
首先eclipse新建一个项目ScrollingActivityProject,因为有android studio,所以直接创建了scrollingActivity,然后将相关布局代码复制到eclipse项目中,主要包括以下代码:
content_scrolling.xml
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.jz_dvb.launcher.view.activity.ScrollingActivity" tools:showIn="@layout/activity_scrolling"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/text_margin" android:text="@string/large_text" /></android.support.v4.widget.NestedScrollView>
activity_scrolling.xml
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="@dimen/app_bar_height" android:fitsSystemWindows="true" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_scrolling" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" app:layout_anchor="@id/app_bar" app:layout_anchorGravity="bottom|end" /></android.support.design.widget.CoordinatorLayout>
dimens.xml
<resources> <dimen name="text_margin">16dp</dimen> <dimen name="app_bar_height">240dp</dimen> <dimen name="fab_margin">16dp</dimen></resources>
styles.xml
<resources> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /></resources>
colors.xml
<resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color></resources>
ScrollingActivity.java
public class ScrollingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }}
基本代码就是这些。
由于CoordinatorLayout、CollapsingToolbarLayout、FloatingActionButton等控件属于support-design,所以需要导入support-design包,而support-design包依赖于support-v7包,所以也需要导入support-v7。支持包在sdk目录AndroidSDK\sdk\extras\android\support\v7,没有的话可以在Android SDK Manager中选择最下面的extra下的Android Support Library更新最新的。
将俩个libary导入eclipse中,support-design依赖support-v7
最后选择自己创建的项目ScrollingActivityProject依赖于support-design即可,项目基本没有报错了,编译通过了,当然如果一切正常运行也可以了。
2.过程中遇到的问题
编译过程中的各种红叉错误,忘了,记不清了,主要是编译通过,但运行各种错误。
2.1找不到类
项目依赖support-design包,support-design包依赖support-v7,理论上来讲不可能找不到,v7jar包展开也可以看的到
原因是因为v4的版本和v7不一致导致,一开始新建项目中有自动生成的android-support-v4.jar,当导入support-v7-appcompat library中也有android-support-v4.jar,建立依赖的时候会提示有重复v4.jar包,当时是直接用新建项目中的v4.jar替换了v7项目中原有的v4.jar,所以导致版本不一致,应该用v7中自带的v4,把新建的项目中的v4.jar直接删了就行。
2.2style问题
原因是AppCompatActivity要用v7的style,Activity的style可以修改为android:theme=”@style/Theme.AppCompat.NoActionBar”
我的到此可以运行完成了,另外有什么问题可以随时探讨。
修改:2.2的问题是由于新建项目中没有定义自身的style导致,上面我已补全,所以不需要修改activity的android:theme=”@style/AppTheme.NoActionBar”,修改了反而会使得Tollbar跟随主题颜色。
效果图
源码地址:
http://pan.baidu.com/s/1i5juXz3 密码:7yww
- eclipse中使用scrollingActivity的过程
- CoordinatorLayout:Android之ScrollingActivity的使用
- Eclipse使用过程中出现java.lang.NoClassDefFoundError的解决方案
- Eclipse使用过程中出现java.lang.NoClassDefFoundError的解决方案
- Eclipse 快捷键使用过程中遇到的两個小问题
- Eclipse使用过程中出现java.lang.NoClassDefFoundError的解决方案
- 记录使用 Eclipse 的过程中出现以下问题
- 在使用eclipse开发android过程中,注释的使用细节
- 在使用eclipse开发android过程中,注释的使用细节
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- eclipse插件findBugs安装及使用过程中遇到的错误
- 使用Eclipse开发Java Web过程中Debug调试的使用方法
- 安装eclipse过程过程中出现的问题
- TensorFlow入门程序MNIST无反应
- 学习封装mvc(九)composer加载
- Face Alignment at 3000 FPS通俗易懂讲解三 全局回归与测试
- Could not load the source for about:blank.[Exception… "Component returned failure code: 0x80470002 (
- 移动技术开发综合实验(二)
- eclipse中使用scrollingActivity的过程
- 总结4 如何在自定义的框架中使用PHP异常和错误机制
- Android学习进阶路线导航线路(Android源码分享)
- 第5章 引用类型(11)单体内置对象
- 高效能人士和碌碌无为者的15个根本性区别
- Toolbar menu 遇到的问题
- linux常用命令
- Native crash后的代码处理流程[dropbox相关]
- Oracle 同步数据库