使用Viewpager时片段无法全屏显示

时间:2018-10-20 06:13:58

标签: android android-studio android-viewpager

我希望Viewpager在全屏中显示片段,而不仅仅是在屏幕的一半显示。过去两天我一直困扰于此问题,因此请帮助我解决此问题。前进。

这是我的活动代码,名为activity_subcategory.xml-

<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
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.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    app:navigationIcon="@drawable/ic_arrow_back"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<!-- our tablayout to display tabs  -->
<android.support.design.widget.TabLayout
    android:id="@+id/tabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:layout_gravity="center_horizontal"
    app:tabMode="scrollable"
    app:tabSelectedTextColor="@color/buttoncolor"
    android:minHeight="?attr/actionBarSize"
    app:tabIndicatorColor="@color/buttoncolor"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

这是我的片段代码,名为singlesubcategory.xml-

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

   <LinearLayout 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="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imgcat"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:adjustViewBounds="true"
        android:layout_margin="5dp"
        android:src="@drawable/laundry1" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/txtcat"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="right"
        android:weightSum="10"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_weight="7"
            android:layout_marginRight="2dp"
            android:text="₹ 30"
            android:gravity="center"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_addtocart"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_weight="1"
            android:layout_marginRight="2dp"
            android:text="0"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_removecart"/>
    </LinearLayout>
</LinearLayout>
</LinearLayout>
    </android.support.v7.widget.CardView>

See this image. i want that card display in full width of screen.

这是我的recyclerview代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rcv"></android.support.v7.widget.RecyclerView>


</LinearLayout>

4 个答案:

答案 0 :(得分:0)

  

更改viewpager的高度

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

答案 1 :(得分:0)

in your xml activity_subcategory.xml 

change parent Linear layout 
<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
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="fill_parent">

更改高度以填充父级。

答案 2 :(得分:0)

  

使用此代码

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/rcv"
    android:layout_gravity="center"
    android:foregroundGravity="center">

</android.support.v7.widget.RecyclerView>

答案 3 :(得分:0)

modalPresentationStyle