0
A
回答
0
這取決於你想添加什麼樣的頂面佈置的。
如果你想添加圖片或查看傳呼機與滑動圖像,那麼它最好使用CollapsingToolbarLayout
與AppBarLayout
裏面CoordinatorLayout
,然後添加您的RecyclerView。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_parentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="260dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorAccent"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:id="@+id/avatar_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorAccent"
android:gravity="center"
android:minHeight="160dp"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<!-- Here you can add your header layout only if its not too big-->
<ImageView
android:id="@+id/myprofile_avatar"
android:layout_width="@dimen/profile_avatar_size"
android:layout_height="@dimen/profile_avatar_size" />
</LinearLayout>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/profile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
-1
你可以做到這一點的方式,包括多個視圖:
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case 0: return new ViewHolder0(...);
case 2: return new ViewHolder2(...);
}
}
0
它可以通過重寫該方法中,getItemViewType(INT位置)來完成這指定膨脹爲回收站視圖
@Override
public int getItemViewType(int position) {
if (position == 0)
return LAYOUT_TYPE_0;
else if (position == 1)
return LAYOUT_TYPE_1;
else
return LAYOUT_TYPE_ITEM;
}
這裏的perticular位置,其佈局是完整適配器代碼
public class RecyclerViewAdapter extends RecyclerView.Adapter {
public static final int LAYOUT_TYPE_0 = 0;
public static final int LAYOUT_TYPE_1 = 1;
public static final int LAYOUT_TYPE_ITEM = 2;
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == LAYOUT_TYPE_0) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_0, parent, false);
return new LayoutPos0(view);
} else if (viewType == LAYOUT_TYPE_1) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_1, parent, false);
return new LayoutPos1(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_common, parent, false);
return new LayoutCommon(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemViewType(int position) {
if (position == 0)
return LAYOUT_TYPE_0;
else if (position == 1)
return LAYOUT_TYPE_1;
else
return LAYOUT_TYPE_ITEM;
}
public class LayoutPos0 extends RecyclerView.ViewHolder {
//your code goes here
}
private class LayoutPos1 extends RecyclerView.ViewHolder {
}
private class LayoutCommon extends RecyclerView.ViewHolder{
}
@Override
public int getItemCount() {
return 100;
}
}
相關問題
- 1. 如何在Android的回收視圖中添加多個視圖
- 2. 將視圖添加到RecyclerView
- 3. 如何在視圖中添加多個集合視圖
- 4. 如何添加多個陣列recyclerview
- 5. 如何在Android中使用recyclerView滾動其他視圖?
- 6. 如何添加多個視圖到UIScrollView
- 7. 如何在Android的滾動視圖中添加更多項目?
- 8. 如何添加3個位置後的額外視圖RecyclerView?
- 9. 如何在地圖視圖中添加多個註釋
- 10. 如何在單個視圖中添加多個模型?
- 11. 如何在android中的其他視圖添加覆蓋視圖?
- 12. 如何在Android視圖中添加自定義視圖?
- 13. 如何在android中添加頁腳視圖到列表視圖?
- 14. 在android中添加多個圖像層
- 15. Android - 如何添加多個陣列到列表視圖
- 16. 如何在單個視圖中添加多個網絡子視圖?
- 17. 添加多個samve視圖
- 18. 將多個視圖添加到視圖
- 19. onClick不工作在多個視圖recyclerView
- 20. 如何在ViewPager中添加多個TextView或其他視圖
- 21. 動態添加視圖到RecyclerView
- 22. 如何使用RecyclerView顯示空視圖?
- 23. 如何使用staggeredGridLayoutManager添加headerview到recyclerview
- 24. 如何添加多個視圖iPad視圖控制器
- 25. 在Android中添加圖片視圖
- 26. 如何在Android中的谷歌地圖添加多個標記?
- 27. 如何在android中的操作欄上添加多個圖標?
- 28. 如何添加多個視圖到Django中的一個模板?
- 29. 如何在Android中使用onItemClicklistener在List視圖中動態添加按鈕?
- 30. 滾動視圖中的多個Recyclerview問題添加不必要的空間
感謝烏爾快速回復艾米特。但是當我從內容頂部進行操作時,recyclerview內容的底部將被聚焦到屏幕的頂部。怎麼做? – Krishna
USE recyclerview.requestFocus(); –