托管viewPager的Android FrameLayout占用所有可用空间

菲皮

在此处输入图片说明

大家好,我正在尝试创建一个“教程”(如来自AirBnb应用程序的该教程),其中包含不同的图像和文本(均托管在Fragment中),并由FrameLayout中的(Fragment)ViewPager管理。正如上面的示例所示,我还希望在屏幕底部显示两个按钮,我的问题是包含ViewPager的FrameLayout占用了所有可用空间,因此隐藏了包含按钮的LinearLayout。

这是一种奇怪的情况,因为布局非常简单,我尝试了不同的方法,但是没有任何解决方案可以解决我的问题。我检查了只有布局的根元素处于fill_parent模式,并且还检查了所有其他布局避免增长到超出其显示信息所需的空间。

以下是一些片段以及Activity和FragmentViewPager显示的每个子片段的xml布局:

activity-tutorial.xml(我尝试将LinearLayout用作根元素而不是RelativeLayout,但没有任何变化)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout
    android:id="@+id/pager_framelayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

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

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/circle_indicator"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="@null" 
        android:layout_gravity="bottom" />
</FrameLayout>

<LinearLayout 
    android:id="@+id/buttons_bottom_layout"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:weightSum="100"
    android:layout_below="@id/pager_framelayout">

    <Button 
        android:id="@+id/sign_up_btn"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="50"
        android:text="Sign UP" />

    <Button 
        android:id="@+id/login_btn"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="50"
        android:text="Login" />
</LinearLayout>
</RelativeLayout>

fragment_tutorial_screen.xml

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

<ImageView 
    android:id="@+id/tutorial_screen_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"/>

<TextView 
    android:id="@+id/tutorial_screen_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/general_padding"
    android:background="@null"
    android:layout_gravity="bottom"/>
</FrameLayout>

以及用于实例化片段并使用info填充视图的Java代码:

TutorialScreenFragment.java

{ //...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Identify and set fields!
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.subfragment_tutorial_screen, container, false);
    image = (ImageView) rootView.findViewById(R.id.tutorial_screen_image);
    title = (TextView) rootView.findViewById(R.id.tutorial_screen_title);
    return rootView;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Populate fields with info!
    if (TutorialActivity.class.isInstance(getActivity())) {
        title.setText(titleResId);
        // Call Glide to load image
        Glide.with(this)
        .load(imageResId)
        .centerCrop()
        .placeholder(R.drawable.image_placeholder)
        .into(image);
    }
}
/...
}

一切正常,点显示当前页面,但按钮根本不显示。这是我的应用程序结果:

在此处输入图片说明

谢谢。

罗姆森

您需要更改布局的行为。首先,将您LinearLayout的父母对齐然后把你放在FrameLayout上面LinearLayout像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout
    android:id="@+id/pager_framelayout"
    android:layout_width="fill_parent"
    android:layout_above="@+id/buttons_bottom_layout"
    android:layout_height="wrap_content">

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

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/circle_indicator"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="@null" 
        android:layout_gravity="bottom" />
</FrameLayout>

<LinearLayout 
    android:id="@+id/buttons_bottom_layout"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:weightSum="100"
    android:layout_alignParentBottom="true">

    <Button 
        android:id="@+id/sign_up_btn"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="50"
        android:text="Sign UP" />

    <Button 
        android:id="@+id/login_btn"
        android:padding="@dimen/general_padding"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="50"
        android:text="Login" />
</LinearLayout>
</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android XML布局-ImageView占用所有空间

使div扩展以占用所有可用空间

Android-AlignParentBottom占据了所有可用空间

Android:评分栏未占用完整的可用空间

如何防止 TextBlock 占用所有可用空间

iOS - 占用水平 UIStackView 中的所有可用空间

CSS:div height占用父级的所有可用空间

如何使绝对定位的div占用所有可用的宽度空间?

如何自动占用CSS网格中的所有可用空间

GoogleMap 可组合占用所有可用的屏幕空间

React Native图像占用了所有可用的垂直空间

占用ConstraintLayout中元素之间的所有可用空间

Android-如何在工具栏中设置项目以填充所有可用空间?

清晰度:是否有建议的方法使clr-datagrid占用所有可用的垂直空间?

Android-没有可用空间

Android ViewPager更改所有图像

Android:如何使自定义视图仅占用可用的屏幕空间?

当其父按钮的高度最小时,如何使按钮占用所有可用空间?

GridBagLayout中的组件放置在中心,而不会占用所有可用空间

使ImageView占用所有可用的垂直空间并增加宽度以在RelativeLayout中按比例放大/缩小

将页眉和页脚设置为内容高度,内容部分将占用所有可用空间

Service Fabric日志占用了所有可用磁盘空间

在同一行上渲染元素,其中输入元素占用所有可用空间

CSS:使列表中的所有<li>宽度相同,并占用100%的可用空间

为什么我的自定义视图试图占用 VStack 中所有可用的垂直空间?

Firebase托管已删除的部署占用空间

我的Android SDK占用太多空间,.temp目录占用90+ GB以上的空间。.temp目录有什么作用?

带有ViewPager的Android ClassNotFoundException

带有ViewPager的Android RecyclerView