OGeek|极客世界-中国程序员成长平台

标题: android - 如何在 Linearlayout 中嵌入 ViewPager 和 LinearLayout? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 06:17
标题: android - 如何在 Linearlayout 中嵌入 ViewPager 和 LinearLayout?

虽然我已将其 layout_height 设置为“100dp”,但内部 LinearLayout 已消失。

<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="match_parent"
    androidrientation="vertical">

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp">
        <SeekBar
            android:layout_width="0dp"
            android:layout_weight="10"
            android:layout_height="match_parent"
            android:id="@+id/seek_bar"/>
        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:id="@+id/toggle"/>
    </LinearLayout>
</LinearLayout>

编辑:我希望内部布局的方向是水平的。所以我将它的 layout_height 设置为 wrap_content。现在,它几乎完成了。但是,SeekBar 出了点问题,缩略图不在垂直条的中心。
enter image description here

<android.support.v4.view.ViewPager
    android:id="@+id/page_pager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    androidrientation="horizontal">
    <SeekBar
        android:layout_width="0dp"
        android:layout_weight="10"
        android:layout_height="match_parent"
        android:id="@+id/seek_bar"/>
    <Button
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:id="@+id/toggle"/>
</LinearLayout>



Best Answer-推荐答案


使用 weight 代替。我已经修改了代码。

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
    androidrientation="vertical">

    <android.support.v4.view.ViewPager
        android:id="@+id/page_pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <!-- app:layout_behavior="@string/appbar_scrolling_view_behavior" -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        androidrientation="horizontal">

        <SeekBar
            android:id="@+id/seek_bar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:id="@+id/toggle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>

关于android - 如何在 Linearlayout 中嵌入 ViewPager 和 LinearLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34114374/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4