1. 滑動不流暢
解決方法一:
recyclerView.setNestedScrollingEnable(false);
解決辦法二:
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
layoutManager.setSmoothScrollbarEnabled(true);
layoutManager.setAutoMeasureEnabled(true);
2. 當NestedScrollView嵌套RecycleView布局由Fragment管理湾笛,F(xiàn)ragment切換時會自動滑動到ReycleView的頂部.
解決方法一:
在NestedScrollView唯一子布局中加入 android:descendantFocusability="blocksDescendants"
--android:descendantFocusability 有三個屬性:
優(yōu)先于子控件獲取焦點 "beforeDescendants"
當子控件不需要焦點時,獲取焦點 "afterDescendants"
覆蓋所有子控件獲取焦點 "blocksDescendants"
解決方法二:
recyclerView.setFocusable(false);
image
3. ScrollView中的布局不能撐滿全屏
解決: 必須ScrollView設置
android:fillViewport="true"
4. android scrollview 自動滾動到頂部或者底部
// 設置默認滾動到頂部
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_UP);
}
});
// 設置默認滾動到底部
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
5. 一個內(nèi)容很長的布局, 加了scrollview會自動滾動到底部的問題
解決:找到scrollview里的其中一個子控件
mTitle.setFocusable(true);
mTitle.setFocusableInTouchMode(true);
mTitle.requestFocus();
6. NestedScrollView與AppBarLayout配合使用時豺鼻,視圖會重疊
NestedScrollView與AppBarLayout配合使用時沫勿,NestedScrollView屬性必須設置layout_behavior值挨约,
如果要使NestedScrollView與AppBarLayout實現(xiàn)聯(lián)動,那前者的layout_behavior屬性一定要設置和
后者的所有根子布局的layout_scrollFlags屬性一定都要設置产雹!
7. NestedScrollView嵌套ListView诫惭, listview只顯示一行數(shù)據(jù)
解決:重寫listview的onMeasure
public class NestedListView extends ListView {
public NestedListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
///< 測量的大小由一個32位的數(shù)字表示,前兩位表示測量模式蔓挖,后30位表示大小夕土,這里需要右移兩位才能拿到測量的大小
int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
僅供參考,有些情況可能還是會有問題,就需要再研究了怨绣。做個記錄角溃,遇到了特殊情況再看看吧。綜合了一些網(wǎng)友的以及自己遇到了的情況篮撑。减细。