使用viewpager时,片段不会全屏显示

问题描述 投票:1回答:4

我希望我的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>
android android-studio android-viewpager
4个回答
0
投票

更改viewpager高度

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

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">

改变高度以填充父母。


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>


0
投票
for view pager use fill parent

 <android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/viewPager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
© www.soinside.com 2019 - 2024. All rights reserved.