滚动型不能与Android的标签式布局工作 [英] ScrollView not working with Tabbed layout in Android

查看:246
本文介绍了滚动型不能与Android的标签式布局工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手,Android和我想的标签式布局使用滚动型。当我包括片段布局到标签视图,当我们向下滚动的最后一个元素没有显示。我尝试了的LinearLayout的高度设置为WRAP_CONTENT但它仍然是行不通的。

I am a newbie to Android and I am trying to use a ScrollView in the Tabbed layout. When I include the fragment layout to the tabbed view, the last element is not showing when we scroll down. I tried setting the height of the "LinearLayout" to "wrap_content" but still it is not working.

理想我只需要一个按键,其他按键都只是用于测试目的增加。

Ideally I needed only one button, other button are added just for testing purposes.

相同的布局工作正常,如果我把它添加到一个活动,而不是一个选项卡视图。

下面是包含滚动型的布局

Here is the layout which contains a ScrollView

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:scrollbars="vertical"
    tools:context="com.adroitminds.tabbedview.Section2">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="First Name" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Last Name" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="First Name1" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Last Name2" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Phone2" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Email2" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Phone" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Email" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Password" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        android:layout_weight="1"
        android:hint="Confirm Password" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_weight="1"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="16dp"
        android:text="Submit" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_weight="1"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="16dp"
        android:text="Submit1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_weight="1"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="16dp"
        android:text="Submit2" />

</LinearLayout>

标签式的活动有问题

<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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    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:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

下面是截图为scenarois

Here are the screenshots for both scenarois

片段的活动 - 做工精细

片段的标签式布局 - 不工作

我可以通过减少边距或EditTexts的大小解决这个问题,但我很想知道我要去的地方wrong.Could请人帮我解决这个问题。

I can resolve this issue by reducing the margins or size of the EditTexts, but I am curious to know where I am going wrong.Could anyone please help me resolving this issue.

我使用最新版本的Andr​​oid Studio的结果的
的minSdkVersion - 18结果
targetSdkVersion - 23

I am using latest version of Android Studio
minSdkVersion - 18
targetSdkVersion - 23

谢谢,结果
卡皮尔

Thanks,
Kapil

推荐答案

这行添加到您的滚动型

app:layout_behavior="@string/appbar_scrolling_view_behavior"

另外从删除相同属性的 android.support.v4.view.ViewPager
该ViewPager应

Also remove the same attribute from android.support.v4.view.ViewPager The ViewPager should be

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

这篇关于滚动型不能与Android的标签式布局工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆