在LinearLayout中使用Gridview和Button [英] Using Gridview and Button in LinearLayout

查看:47
本文介绍了在LinearLayout中使用Gridview和Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中尝试在gridview下的linearview中添加按钮.但是,当我执行我的应用程序时,我只看到gridview,没有按钮项.因此,这可能是基本的错误,但我看不到.

I tried add button below gridview in linearlayout at following code. But when i execute my app i only see gridview there is no button item. So it may basic mistake but i can't see it.

<?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占用的空间之外的所有空间.

Change the orientation of your LinearLayout to vertical. I suspect you're not seeing the Button because the GridView takes up all horizontal space, then the LinearLayout adds the Button in a place off the screen that's not visible. You also may want to change the layout_height of the GridView to "0dip" and give it the `android:layout_weight=1' attribute so that it will fill all space except that taken up by the Button.

这篇关于在LinearLayout中使用Gridview和Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆