在android工具栏下方添加视图
我以编程方式在ViewPager中添加视图,但这样做时,我的布局不会从actionbar下面开始。它与actionbar重叠 这是应用程序的屏幕截图 在我的寻呼机适配器中,我编写了以下代码 ProductPagerAdapter.java fragment_product.xml 活动xml在android工具栏下方添加视图,android,android-layout,android-viewpager,android-toolbar,Android,Android Layout,Android Viewpager,Android Toolbar,我以编程方式在ViewPager中添加视图,但这样做时,我的布局不会从actionbar下面开始。它与actionbar重叠 这是应用程序的屏幕截图 在我的寻呼机适配器中,我编写了以下代码 ProductPagerAdapter.java fragment_product.xml 活动xml 请告诉我如何以编程方式启动操作栏下方的布局。尝试将app:layout\u behavior=@string/appbar\u scrolling\u view\u behavior添加到activity
请告诉我如何以编程方式启动操作栏下方的布局。尝试将app:layout\u behavior=@string/appbar\u scrolling\u view\u behavior添加到activity.xml中的ViewPager中。当您使用CoordinatorLayout时,它会将视图放置在彼此上方,就像一个框架布局,上面有最近添加的子视图。要解决您的问题,您必须将android:layout_marginTop=?attr/actionBarSize添加到您的ViewPager:
你能添加你的活动xml吗?请看我编辑的问题Android:layout_marginTop=?attr/actionBarSize这节省了我很多时间。
@Override
public Object instantiateItem(ViewGroup container, int position) {
rate = list.get(position);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.fragment_product, container,false);
tvProdName = (TextView) v.findViewById(R.id.tvProdName);
tvProdAmount = (TextView) v.findViewById(R.id.tvProdAmount);
tvProdDesc = (TextView) v.findViewById(R.id.tvProdDesc);
ivProdImage = (ImageView) v.findViewById(R.id.ivProdImage);
tvProdName.setText(rate.Name);
tvProdAmount.setText(rate.amount);
tvProdDesc.setText(rate.longDescription);
Picasso.with(context).load(rate.image).into(ivProdImage);
((ViewPager) container).addView(v);
return v;
}
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/content_details"/>
</LinearLayout>
<?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.ashishkudale.linksolutions.DetailsActivity">
<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_details"/>-->
<android.support.v4.view.ViewPager
android:id="@+id/productPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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>
<android.support.v4.view.ViewPager
android:id="@+id/productPager"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent" />