我有一个<div class="log-container">
<div id="shell-header">
<div class="logo-wrapper">
<img src="https://s-media-cache-ak0.pinimg.com/236x/f7/0a/f6/f70af6169bbe3f8346e64a25d54bafea.jpg" class="logo">
</div>
<div class="title-wrapper">
<div class="log-shellHeaderTitle">Dashboard</div>
</div>
<div class="log-langButton">
<div id="log-LangButtSwitch">
<span class="log-switchHandle"></span>
<span class="log-switchLabels"></span>
</div>
</div>
<div class="avatar-wrapper">
<img class="avatar" src="https://www.talentenportaalhellendoorn.nl/thumbnails/man.png">
<div class="log-toolContainer">
<div class="log-popover">
<a href="#">Profile</a>
<a href="#about">Log out</a>
</div>
</div>
</div>
</div>
</div>
,我想在底部制作一个RecyclerView
如果它是..要清楚,不是屏幕的底部,而是{{1的底部因此,您必须滚动ImageView
才能转到RecyclerView
。
RecyclerView
是否必须属于ImageView
答案 0 :(得分:0)
这样的东西?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="@+id/recycler"/>
</RelativeLayout>
关键是向ImageView添加ndroid:layout_below="@+id/recycler"
。
修改强>
您也可以尝试这样的事情。首先创建从CoordinatorLayout.Behavior扩展的类,然后将新行为附加到ImageView。请记住,RecyclerView和Image View必须是CoordinatorLayout的子项。
public class FixedBottomViewBehavior extends CoordinatorLayout.Behavior<View> {
public FixedBottomViewBehavior() {
}
public FixedBottomViewBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return dependency instanceof RecyclerView;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
if (ViewCompat.isLaidOut(parent)) {
//attach our bottom view to the bottom of CoordinatorLayout
child.setY(parent.getBottom() - child.getHeight());
//set bottom padding to the dependency view to prevent bottom view from covering it
dependency.setPadding(dependency.getPaddingLeft(), dependency.getPaddingTop(),
dependency.getPaddingRight(), child.getHeight());
}
return false;
}
}
然后在xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_behavior="your.package.address.FixedBottomViewBehavior"/>
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:0)
1)为页脚创建一个视图
if (viewType == MY_FOOTER_VIEW) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_list_item_footer, parent, false);
FooterViewHolder footerViewHolder= new FooterViewHolder(v);
return vh;
}
//your regular viewholder inflation
2)现在onCreateViewHolder()检查正确的viewholder 根据需要给页脚或常规查看者充气:
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
try {
if (holder instanceof NormalViewHolder) {
NormalViewHolder vh = (NormalViewHolder) holder;
vh.bindView(position);
} else if (holder instanceof FooterViewHolder) {
FooterViewHolder vh = (FooterViewHolder) holder;
}
} catch (Exception e) {
e.printStackTrace();
}
}
3)执行正确的绑定:
return data.size() + 1;
4)on getItemCount()返回+1元素
@Override
public int getItemViewType(int position) {
if (position == data.size()) {
// This is where we'll add footer.
return FOOTER_VIEW;
}
return super.getItemViewType(position);
}
5)覆盖getItemViewType()以标识您的新类型 页脚。
{{1}}