平板电脑上的Viewpager即使在我说匹配父级后也没有全宽。它们只显示屏幕的一半。
我尝试了所有方法使其全宽,但根本没有出现。有人可以指导我解决这个问题。以下是我尝试过的详细信息。
我在里面添加了xml文件:layout-w600dp-land
<RelativeLayout
android:id="@+id/pagerIndicator"
android:layout_width="match_parent"
android:layout_height="145dp"
android:orientation="horizontal">
<android.support.v4.view.ViewPager
android:id="@+id/myviewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<FrameLayout
android:id="@+id/progressContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_centerVertical="true">
<com.ylg.others.ProgressWheel
android:id="@+id/progress_wheel"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:visibility="gone"
app:matProg_barColor="@color/progressbar"
app:matProg_progressIndeterminate="true" />
</FrameLayout>
</RelativeLayout>
代码:
private class MyPagerAdapter extends PagerAdapter
{
@Override
public int getCount()
{
return NumberOfPages;
}
@Override
public boolean isViewFromObject(View view, Object object)
{
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position)
{
progressContainer.setVisibility(View.GONE);
progress_wheel_layout.setVisibility(View.GONE);
loadingtext.setVisibility(View.GONE);
ImageView imageView = new ImageView(getActivity());
Glide.with(getContext().getApplicationContext())
.load(bannerItems.get(position).getbannerImage())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fitCenter()
.crossFade()
.into(imageView);
LayoutParams imageParams = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
imageView.setLayoutParams(imageParams);
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.VERTICAL);
LayoutParams layoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
layout.addView(imageView);
final int page = position;
layout.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),
"Page " + page + " clicked",
Toast.LENGTH_LONG).show();
}});
container.addView(layout);
return layout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
我打电话给mypager这是:
viewPager = (ViewPager) rootView.findViewById(R.id.myviewpager);
myPagerAdapter = new MyPagerAdapter();
viewPager.setAdapter(myPagerAdapter);
NumberOfPages = bannerItems.size();
myPagerAdapter.notifyDataSetChanged();