您的位置:首页 > 移动开发 > Android开发

第一个android客户端笔记

2015-08-30 17:07 441 查看

主页面



采用时下比较流行的主页面框架,bottomTap加Fargment组成.最初有考虑的是ViewPager,不过考虑到中间的页面还是不要左右滑动的好,使用Fragment来实现.

整体布局为SwipeRefreshLayout加listView组成.

main_layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.erlema.activity.MainActivity" >

<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<include layout="@layout/tap_layout"/>

</LinearLayout>


第一个页面的Fragment布局
<?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" >
<ViewStub
android:id="@+id/loadinglayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout="@layout/loading" />

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/indext_swp"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ListView
android:id="@+id/mytopic"
android:layout_width="match_parent"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_weight="1" >
<requestFocus />
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>


可以看到,上面可以左右滑动的图片轮播并没有出现在FragMent的布局中,因为我想要的效果是整个页面可以向上滑动,包括上面的ViewFLipper.
最初的布局是用一个ScrollLayout将viewFlipper和listview都包含进去,但listView和ScrollLayout组合时出现了bug,listView 只能显示一行,给listView设置具体的高度时又发现顶部的viewflipper并不会随之滚动. 在百度了一轮后发现有人建议将ViewFLipper当做Headveiw加载到listVew中去,发现效果不错便使用了.

顺便说下,SwipeRefreshLayout 和listView貌似也有冲突,当swipeRefresh正在刷新时点击listview会出现程序崩溃的现象.不知道有没有大神能告诉我原因.我暂时的解决方法是当他正在刷新时将lsitveiw的enable设为false.

新的问题又来了.由于第一次使用Viewflipper,发现他给的接口真的很少,比如发现没有接听页面滚动改变的接口,这让我的图片指示器不知如何实现.网上有人使用自定义Viewflipper来实现,可是我自定义view还不是很熟悉.无意中发现有人在Viewflipper的进入动画中实现图片指示器,感觉很符合我的心意.
viewFlipper.getInAnimation().setAnimationListener(
new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
<strong>	SetMark(viewFlipper.getDisplayedChild());</strong>
}


暂时记录到此.等待代码继续完善后回来记录.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: