Reputation: 133
main activity xml
<?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.apuroopa.homework5_apuroopa.ActionBar_Activity"
android:id="@+id/container">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_action_bar_" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
///cardview layout xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fffffff0"
>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_toRightOf="@+id/selection"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_toLeftOf="@+id/image"
android:layout_marginLeft="10dp"/>
<CheckBox
android:id="@+id/selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="@id/title"
/>
<ImageView
android:id="@+id/image"
android:layout_width="80dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:scaleType="fitXY"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<?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.apuroopa.homework5_apuroopa.ActionBarFragment">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_action_bar_fragment" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.CoordinatorLayout>
//Main Activity java
public class ActionBar_Activity extends AppCompatActivity implements Fragment_RecyclerView.OnListItemSelectedListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_bar_);
Fragment mcontent = Fragment_RecyclerView.newInstance(0);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar=getSupportActionBar();
Fragment_RecyclerView FR = new Fragment_RecyclerView();
getSupportFragmentManager().beginTransaction().add(R.id.container,mcontent)
//(Fragment_RecyclerView.newInstance(0)," ")
.commit();
}
I have a menu file inflated in activity. A Recyclerview fragment
is added to the activity. Each row in recyclerview fragment consists of cardview layout. My recyclerview is overlapping the menu options as shown in the picture. The toolbar is placed above recyclerview in the layout file.
Upvotes: 1
Views: 646
Reputation: 348
First give an id to android.support.design.widget.AppBarLayout
Then
<android.support.v7.widget.RecyclerView
android:layout_below=@id/app_bar_layout_id/>
Upvotes: 0
Reputation: 81
add app:layout_behavior="@string/appbar_scrolling_view_behavior"
in cardview tag
Upvotes: 1
Reputation: 36
Put CardView container in RelativeLayout:
<RelativeLayout...>
<android.support.v7.widget.CardView .....>
</android.support.v7.widget.CardView>
</RelativeLayout>
Upvotes: 0