【问题标题】:Android - Last view in RelativeLayout disappearsAndroid - RelativeLayout 中的最后一个视图消失
【发布时间】:2020-07-03 07:16:45
【问题描述】:

我想在片段 1 中显示一个按钮,在这个 gridView 下面我们有另一个按钮。

一切都被包裹在一个像这样的RelativeLayout中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
    android:id="@+id/gridview_bouton_new"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/creer_categorie"
    android:layout_centerHorizontal="true"></Button>

<GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:horizontalSpacing="8dp"
    android:numColumns="3"
    android:verticalSpacing="8dp"
    android:padding="10dp"
    android:layout_below="@+id/gridview_bouton_new">
</GridView>

<Button
    android:id="@+id/gridview_bouton_valider"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/valider"
    android:layout_below="@+id/gridView"
    android:layout_centerHorizontal="true"></Button>

它工作正常,直到我在 gridView 中有很多项目。 超过 6 行的片段可以垂直滚动,但最后一个按钮消失了!

我尝试将所有内容嵌套在 ScrollView 中,但只显示第一行....

如果有人有解决方案,那将非常有帮助!

【问题讨论】:

    标签: android gridview layout scrollview android-relativelayout


    【解决方案1】:

    考虑为此目的使用 RecyclerView:https://developer.android.com/guide/topics/ui/layout/recyclerview

    GridView 现已弃用,不建议使用。也很有限。

    另一方面,RecyclerView 让您能够动态地显示任意数量的项目。

    您也可以使用 GridLayoutManager 来实现所需的网格外观:https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/GridLayoutManager

    【讨论】:

      【解决方案2】:

      您可以尝试使用 LinearLayout 而不是 RelativeLayout 并使用 ScrollView 作为父级。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-26
        • 1970-01-01
        • 1970-01-01
        • 2012-05-11
        • 2014-07-25
        • 1970-01-01
        • 2020-11-24
        相关资源
        最近更新 更多