A. android 向上滑動srcollview 怎麼隱藏viewpager裡面的布局
借用兩個庫來快速完成
1. ViewPagerIndicator
2. ObservableScrollView
將兩個庫引入項目中去,快速的搭建一個ViewPager框架後,在ViewPager每頁對應的Fragment的布局中增加一個ListView,這個ListView使用ObservableScrollView庫中的ListView
主布局代碼,使用線性布局,上方放置indicator,下方放置ViewPager
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="50dp" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
-Fragment代碼,放置一個ObservableListView
<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="${relativePackage}.${activityClass}" >
<cn.e.zafu.view.observableview.ObservableListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
業務邏輯代碼
在Activity中初始化indicator和viewpager,然後再fragment中處理viewpager中內容即listview手勢上下滑動與indicator的聯動。在onCreateView中管理indicator,並獲取其高度
indicator = (TabPageIndicator) getActivity().findViewById(indicatorId);
//獲得indicator高度
indicator.post(new Runnable() {
@Override
public void run() {
height=indicator.getHeight();
Log.d("TAG", "height:"+height);
}
});
關聯listview並設置監聽器
listView = (ObservableListView) view.findViewById(R.id.list);
listView.setScrollViewCallbacks(this);
fragment實現對應的介面
implements ObservableScrollViewCallbacks
實現的方法如下
@Override
public void onScrollChanged(int scrollY, boolean firstScroll,
boolean dragging) {
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
在onUpOrCancelMotionEvent方法中完成顯示和隱藏indicator
//獲得高度的另一種方法
/*if(height==0){
height=indicator.getHeight();
Log.d("TAG", "height:"+height);
}*/
//如果手勢向上則隱藏,手勢向下則顯示
if (scrollState == ScrollState.UP) {
//如果顯示的並且動畫沒有在進行,則隱藏
if (isIndicatorShow&&!isShowing) {
hideIndicator();
}
} else if (scrollState == ScrollState.DOWN) {
//如果沒顯示的並且動畫沒有在進行,則顯示
if (!isIndicatorShow&&!isShowing) {
showIndicator();
}
}
完成顯示和隱藏的函數,使用屬性動畫完成一個過渡效果
public void showIndicator() {
//屬性動畫translationY
ObjectAnimator animator = ObjectAnimator.ofFloat(indicator, "translationY",
0f);
//持續時間
animator.setDuration(500);
//插值器,減速
animator.setInterpolator(new DecelerateInterpolator(2));
//監聽器
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//不斷增加indicator所在viewgroup的高度
LayoutParams layoutParams = indicator.getLayoutParams();
float v=(Float) animation.getAnimatedValue();
Log.d("TAG","show:"+v);
layoutParams.height=height+(int)v;
//重新布局
indicator.requestLayout();
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
//動畫開始後設置為true
isShowing=true;
super.onAnimationStart(animation);
}
@Override
public void onAnimationEnd(Animator animation) {
//動畫結束後設置為false
isShowing=false;
//顯示後設置為已顯示
isIndicatorShow = true;
super.onAnimationEnd(animation);
}
});
//開始動畫
animator.start();
}
public void hideIndicator() {
ObjectAnimator animator = ObjectAnimator.ofFloat(indicator, "translationY",-height);
animator.setDuration(500);
//加速插值器
animator.setInterpolator(new AccelerateInterpolator(2));
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//不斷減小indicator所在viewgroup的高度
LayoutParams layoutParams = indicator.getLayoutParams();
float v=(Float) animation.getAnimatedValue();
Log.d("TAG","hide:"+v);
layoutParams.height=height+(int)v;
indicator.requestLayout();
}
});
//同顯示
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
isShowing=true;
super.onAnimationStart(animation);
}
@Override
public void onAnimationEnd(Animator animation) {
isShowing=false;
isIndicatorShow = false;
super.onAnimationEnd(animation);
}
});
animator.start();
}
所有用到的變數
private View view = null;//存儲fragemnt的視圖
private TabPageIndicator indicator = null;//indicator
private ObservableListView listView = null;//listview
private int indicatorId;//indicator對應的id值
private int height=0;//indicator高低
private boolean isIndicatorShow = true;//是否顯示
private boolean isShowing=false;//動畫是否正在進行
B. android想實現的功能是,頂部圖片在listview上滑時隱藏,中間的tab標簽在listvi
隱藏圖片可以是view.setvisibility(view.gone)
監視listview的滑動可以是listview.setonscrolllistener
C. android上拉現實頭部和底部下拉隱藏
https://github.com/wasabeef/awesome-android-ui
希望能幫到樓主。
https://github.com/ksoichiro/Android-ObservableScrollView
這個應該是樓主需要的要求。
D. android 怎麼隱藏狀態欄和顯示狀態欄
Android任務欄圖標隱藏方法/步驟:
1、首先看到任務欄;
2、右擊任務欄,在下拉菜單中選擇屬性,會出現一個開始與任務欄對話框;
3、在任務欄外觀中選擇自動隱藏任務欄;
4、選擇完成後點擊確定,任務欄就能夠自動隱藏了;
E. android打開activity會有抽屜上拉效果,怎麼取消或者隱藏
兩個activity切換之間的動畫是可以自定義的,只需要在activity中加上overridePendingTransition(enterAnim, exitAnim)就OK了,enterAnim是當前activity加入的動畫,exitAnim是出的。頁面的飛入效果是不能去掉的,這是系統默認的,如果你想實現沒有動畫的效果,只能用另外的在一個全局布局中用addView和removeView來實現了。
F. android中怎樣隱藏滾動條
android中隱藏滾動條的方法:
1. 在<ListView>標簽中設置屬性,android:fastScrollEnabled="false"
2. 以下屬性scrollbars可以設置為none也可以不設置為none。效果會有點不同。根據具體情況決定是否設置為none,android:scrollbars="none"
3. 屬性fastScrollEnabled說明:
Enables the fast scroll thumb that can be dragged to quickly
scroll through the list. [boolean]
譯:允許fast scroll thumb可以拖動來快速滾動列表。
4. 屬性scrollbars說明:
Defines which scrollbars should be displayed on scrolling or not.
譯:定義在scrolling時哪個滾動條應該顯示出來,或者不顯示。
G. Android開發怎麼動態隱藏頂部的Tab,求大神,怎麼實現這種效果
android 阻尼效果,這個需要自己去寫控制項去實現
我這有個demo
跟你這個類似,下拉的時候,顯示出一堆的東西,上拉就隱藏
H. Android怎麼做出上拉隱藏天氣 下拉顯示天氣信息 類似於交行首頁界面
對於要求在Android上做出上拉隱藏天氣 下拉顯示天氣信息的界面,首先要看手機系統以及自帶的天氣軟體支持不支持這種功能,如果支持的話,直接在軟體里設置就可以了。類似這樣:
墨跡天氣就支持這樣的功能。
I. 安卓 有什麼可以隱藏虛擬按鍵又能上拉顯示虛擬按鍵的軟體嗎
你可以下載一個(自動軟鍵隱藏)oppo手機親測可用。