android - 如何在 Linearlayout 中嵌入 ViewPager 和 LinearLayout?

标签 android android-layout

尽管我已将其 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"
    android:orientation="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"
    android:orientation="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>

最佳答案

改用权重。我修改了代码。

<?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"
    android:orientation="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"
        android:orientation="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/

相关文章:

android - 复合布局是否总是需要自己的类?

jquery - HTML5 布局,如 Android Tab 和 Swipe 布局

java - android eclipse错误二进制xml文件错误膨胀类android.widget.relativelayout

android - 在 android 中使用兼容的库

Android无法录制清晰语音的来电

android - 如何从其他类调用 onCreate 方法?

android - 哪个 EditText 方法监听输入的每个字母

android - 如何在 Android 布局中创建 TAB View

Android KSoap2 和数组问题

android - 使用 JDBC 从 android 中的 mySQL 检索多个数据