android - 在 LinearLayout 中使用 Gridview 和 Button

标签 android android-layout android-view

我尝试在以下代码的线性布局中的 gridview 下方添加按钮。但是当我执行我的应用程序时,我只看到 gridview 没有按钮项。所以它可能是基本错误,但我看不到。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="#2a2a2a"
         >
            <GridView 
                    android:id="@+id/grid_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:columnWidth="150dp"
                    android:numColumns="auto_fit"
                    android:horizontalSpacing="10dp"
                    android:verticalSpacing="10dp"
                    android:stretchMode="columnWidth"
                    android:gravity="center"></GridView>
            <Button 
                    android:id="@+id/button1" 
                    android:layout_width="wrap_content" 
                    android:layout_height="50dp" 
                    android:text="@string/cam_string" />

    </LinearLayout>

最佳答案

LinearLayout 的方向更改为 vertical。我怀疑您没有看到 Button,因为 GridView 占据了所有水平空间,然后 LinearLayout 将 Button 添加到屏幕外不可见的位置。您可能还想将 GridView 的 layout_height 更改为“0dip”,并为其指定 `android:layout_weight=1' 属性,以便它填充除 Button 占用的空间之外的所有空间。

关于android - 在 LinearLayout 中使用 Gridview 和 Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17219742/

相关文章:

android - 如何在 Android 中创建像图像一样的进度条

android - Android中的文字闪烁,用最简洁的Kotlin

java - 关闭抽屉导航箭头动画

android - android中的对象识别

android - 用于具有多个子项目的项目列表的自定义适配器?

java.lang.NoClassDefFoundError : Failed resolution of: Ljava/lang/invoke/MethodHandles$Lookup 错误

android - 我在 NetBeans 中看不到图形布局 android

android - 应用不同颜色的样式

android:每次单击选项卡时内存使用量都在增加(使用 Activity 组时)

Java Android 线程,同一个线程工作两次