我有一个带有viewpager的tablayout,它包含四个片段,前三个标签(片段)工作正常 . 但最后一个片段的高度不能减少 . 其布局仅包含固定大小高度的Imageview . 但片段高度始终大于imageview . 我试图将imageview放在框架布局和linearlayout中,尝试所有高度可能性:match_parent,wrap_content和固定大小的高度但是,它不起作用 . 我试图将maxHeight添加到imageview而没有运气 . 我猜测问题可能是视图寻呼机,因为它可能正在测量其他片段的高度并坚持这个高度,但为什么其他片段工作正常 . 所以我需要你的帮助 . 在此先感谢这是我的最后一个片段布局:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="260dp"
android:maxHeight="260dp"
android:scaleType="centerCrop"
android:src="@drawable/gs350f"/>
这是viewpager布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/car_overview_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/rounded_corner"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/transparent"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/high" />
<com.myproject.ui.custom.NonSwipeableViewPager
android:id="@+id/overview_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/car_overview_tabs" />
最后这是NonSwipeableViewPager类:
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override public boolean onInterceptTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
@Override public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}