【问题标题】:Split layout into two?将布局一分为二?
【发布时间】:2016-06-16 17:35:03
【问题描述】:

我想将我的片段分成两个相对布局,并在顶部有一个 TabLayout。我的问题是选项卡布局与顶部的 RelativeLayout 重叠,使其看起来不到 50%:

我希望它看起来如何。两个部分都应该占 50% 不包括标签

目前,选项卡是顶部相对布局的 50% 的一部分,因此底部看起来更大。我怎样才能解决这个问题?这是 XML:

android:orientation="vertical"
android:windowSoftInputMode="adjustNothing">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="#3ed682">

        ...

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="#ae25fd">
        ...

</RelativeLayout>

尽管我的选项卡布局位于顶部,但我如何才能将这两个部分平均拆分?

【问题讨论】:

  • 将您的标签布局放在顶部,然后在标签布局下方放置一个垂直线性布局,然后在线性布局内放置两个相对布局,每个布局权重为 1。
  • @LikeWhiteOnRice 我有,但是标签布局没有添加到片段的 XML 中,它是添加到 MainActivity 的 XML 中的。
  • 您的 ViewPager 在您的活动 XML 中是什么样的?它应该有一个 0dp 的高度,你的 TabLayout 应该有一个 wrap_content 的高度。
  • @LikeWhiteOnRice &lt;android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt;
  • 在您的相关布局中尝试android:layout_height="0dp" android:layout_weight="1"

标签: java android xml string performance


【解决方案1】:

在活动布局中更改您的 ViewPager

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

【讨论】:

    猜你喜欢
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多