【问题标题】:Making the Button's align_parentBottom = "true" when other view's height is not Zero当其他视图的高度不为零时,使按钮的 align_parentBottom = "true"
【发布时间】:2015-10-12 17:00:33
【问题描述】:

首先标题可能看起来毫无意义,但我不知道如何在标题中很好地描述我的问题。

我有一个Relative layout,其中有2 buttons(过去的比赛和即将举行的比赛)和2 listviews。每当按下按钮时,如果关联的列表视图已经展开,则它会折叠(高度为零),否则会发生相反的情况。 ( i used this solution)

问题: 当我在 5 英寸屏幕手机上运行它时,一切都很好。请看下图:

[![][2]][2]

但如果我在 10 英寸平板电脑上运行它,它看起来像这样:

[![][3]][3]

当它在小于 5 英寸的手机上运行时也会发生同样的情况。

我的问题

  • 我需要为平板电脑制作另一个布局吗?像在 layout-large 文件夹中一样?

  • 或者我可以在 Jave 文件中使用一些事件,当列表视图未折叠时动态设置按钮对齐父底部属性。

  • 或者它可以在我当前的 XML 中修复

下面是我寻求帮助的那部分的代码

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="10dp"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/btnPastGames"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            android:background="@color/YellowColor"
            android:text="Past Games"
            android:textAllCaps="false"
            android:textSize="15sp" />

        <ListView
            android:id="@+id/lvPastGames"
            android:layout_width="match_parent"
            android:layout_height="255dp"
            android:layout_below="@+id/btnPastGames"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="17dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="5dp"
            android:divider="@null" />

        <Button
            android:id="@+id/btnUpcommigGames"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_below="@+id/lvPastGames"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            android:background="@color/YellowColor"
            android:text="Up Coming Games"
            android:textAllCaps="false"
            android:textSize="15sp" />

        <ListView
            android:id="@+id/lvUpcomingGames"
            android:layout_width="match_parent"
            android:layout_height="255dp"
            android:layout_below="@+id/btnUpcommigGames"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="17dp"
            android:layout_marginStart="17dp"
            android:divider="@null" />

    </RelativeLayout>

</LinearLayout>

如果你们能给我一些建议,让我的用户界面可以在所有屏幕尺寸和密度上运行,我将非常感激

感谢任何愿意帮助我的人

【问题讨论】:

  • 您希望 btnUpcommigGames 按钮始终位于屏幕底部?
  • 不,当 lvPastGames 折叠时,按钮 btnUpcommingGames 应该在 btnPastGames 下方,否则它应该停留在底部。

标签: android xml user-interface


【解决方案1】:

您正在尝试解决ExpandableListView 的功能。请看以下页面:

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

【讨论】:

    猜你喜欢
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2017-08-22
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2021-02-07
    相关资源
    最近更新 更多