【发布时间】:2016-12-04 17:40:00
【问题描述】:
我正在以编程方式在 ViewPager 中添加视图但是当我这样做时,我的布局不会在操作栏下方开始。它与操作栏重叠。
这是应用程序的屏幕截图。
在我的寻呼机适配器中,我编写了这段代码。
ProductPagerAdapter.java
@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;
}
fragment_product.xml
<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
<?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>
能否告诉我如何以编程方式在操作栏下方开始布局。
【问题讨论】:
-
你能添加你的活动 xml 吗?
-
查看我编辑的问题
标签: android android-layout android-viewpager android-toolbar