我在应用中有两个工具栏覆盖的布局。在每个布局中,我都尝试使用android:layout_below="@id/toolbar
或<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.aaron.walkingtourtest09feb.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/app_bar_layout"
android:theme="@android:style/Theme.Material">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:background="#607D8B"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
,但没有运气。我怎样才能解决这个问题?
通过触摸菜单项来调用回收器视图,并通过rv adpater和视图持有者类进行充气。到目前为止,我没有其他问题,除了覆盖视图的工具栏。
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
tools:context="com.example.test09feb.MainActivity"
tools:showIn="@layout/app_bar_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<fragment
android:id="@+id/listFragment"
android:tag="unique_tag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.test09feb.MainActivity$ExampleFragment" >
</fragment>
content_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardview_light_background"
android:animateLayoutChanges="true"
android:padding="6dp">
<android.support.v7.widget.RecyclerView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rv">
</android.support.v7.widget.RecyclerView>
Recyclerview_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/cv"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#EEEEEE"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="@+id/subject_photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/subject_photo"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textColor="@android:color/black"
android:textSize="16sp"/>
<TextView
android:id="@+id/subject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/subject_name"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#777777"
/>
<Button
android:id="@+id/card_button_left"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/subject_text"
android:layout_toLeftOf="@+id/card_button_right"
android:text="@string/watch"
/>
<Button
android:id="@id/card_button_right"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/subject_text"
android:text="@string/read"/>
<TextView
android:id="@+id/expanded_subject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/card_button_right"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#777777"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
cards.xml:
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.SubjectViewHolder> {
List<Subject> subjects;
static SubjectViewHolder svh;
View v = null;
Context cxt;
private static MyListener listener;
public interface MyListener {
void onClick(View itemView, int viewPosition);
}
RVAdapter(List<Subject> subjects, Context cxt) {
this.subjects = subjects;
this.cxt = cxt;
}
public void setOnClickListener(MyListener listener) {
this.listener = listener;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public SubjectViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cards, viewGroup, false);
svh = new SubjectViewHolder(v);
return svh;
}
String[] localLinks = {
"http://192.168.11.111:8000/pic1.png",
"http://192.168.11.111:8000/pic2.jpg",
"http://192.168.11.111:8000/pic3.png",
"http://192.168.11.111:8000/pic4.jpg",
"http://192.168.11.111:8000/pic5.png",
"http://192.168.11.111:8000/pic6.jpg",
"http://192.168.11.111:8000/pic7.png",
"http://192.168.11.111:8000/pic8.jpg",
"http://192.168.11.111:8000/pic9.png",
"http://192.168.11.111:8000/pic10.jpg",
"http://192.168.11.111:8000/pic11.png",
"http://192.168.11.111:8000/pic12.png",
"http://192.168.11.111:8000/pic13.png",
"http://192.168.11.111:8000/pic14.png",
};
@Override
public void onBindViewHolder(SubjectViewHolder subjectViewHolder, int i) {
subjectViewHolder.subjectName.setText(subjects.get(i).subjectName);
subjectViewHolder.subjectText.setText(subjects.get(i).subjectText);
Picasso.with(cxt).load(localLinks[i]).into(subjectViewHolder.subjectPhoto);
subjectViewHolder.expandedSubjectText.setText(subjects.get(i).expandedSubjectText);
subjectViewHolder.expandedSubjectText.setVisibility(View.GONE);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return subjects.size();
}
public static class SubjectViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView subjectName;
TextView subjectText;
TextView expandedSubjectText;
ImageView subjectPhoto;
Button leftButton;
Button rightButton;
SubjectViewHolder(final View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
subjectName = (TextView) itemView.findViewById(R.id.subject_name);
subjectText = (TextView) itemView.findViewById(R.id.subject_text);
expandedSubjectText = (TextView) itemView.findViewById(R.id.expanded_subject_text);
subjectPhoto = (ImageView) itemView.findViewById(R.id.subject_photo);
leftButton = (Button) itemView.findViewById(R.id.card_button_left);
rightButton = (Button) itemView.findViewById(R.id.card_button_right);
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (expandedSubjectText.getVisibility() == View.GONE) {
expandedSubjectText.setVisibility(View.VISIBLE);
} else {
expandedSubjectText.setVisibility(View.GONE);
}
// Triggers click upwards to the adapter on click
if (listener != null)
v.findViewById(R.id.card_container);
listener.onClick(rightButton, svh.getAdapterPosition());
}
});
leftButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Triggers click upwards to the adapter on click
if (listener != null)
listener.onClick(leftButton, svh.getAdapterPosition());
}
});
}
}}
RVAdapter:
{{1}}
根据建议添加appbar_scrolling_view_behavior的结果。一个空白栏覆盖了刚刚显示动画的textview。
答案 0 :(得分:8)
您必须将以下属性添加到content_main.xml
中的父视图app:layout_behavior="@string/appbar_scrolling_view_behavior"
像这样:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test09feb.MainActivity"
tools:showIn="@layout/app_bar_main"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
答案 1 :(得分:6)
您的工具栏高度定义为:$(function () {
$('#datetime1')
.attr('data-date-defaultdate', $('#datetime1 input').attr('value'))
.datetimepicker({
format: 'DD MMM YYYY HH:mm',
defaultDate: $('#datetime1 input').attr('value'),
viewDate: 'true'
});
$('#datetime2')
.attr('data-date-defaultdate', $('#datetime2 input').attr('value'))
.datetimepicker({
format: 'DD MMM YYYY HH:mm',
defaultDate: $('#datetime2 input').attr('value')
});
});
所以我在列表视图中添加了带有这些值的上边距:
android:layout_height="?attr/actionBarSize"
在我正在处理的应用程序中为我工作。