开发者

Android GridView hides my Buttons

I have a LinearLayout in my android application.

Worked well with just the two Buttons - but when I added the GridView, it now hides the two Buttons - regardless if I put them above or below the GridView

Can anyone help ?

<?xml version="1.0" encoding="utf-8"?>

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gridview"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:numColumns="4"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>

<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5px"
android:layout_width="fill_parent"
android:text="@string/week" />
<Button android:layout_weight="1"
android:l开发者_如何学Cayout_marginTop="5px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/day" />


I solved this - it was because the root level LinearLayout was set with an orientation of horizontal.

I changed this to 'vertical' and then wrapped the two Button elements in their own LinearLayout with 'horizontal' orientation - all works as I needed now.

Here is the resulting XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff">

        <Button android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="5px"
            android:layout_width="fill_parent"
            android:text="@string/week" />
        <Button android:layout_weight="1"
            android:layout_marginTop="5px"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="@string/day" />
</LinearLayout>

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:numColumns="4"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"/>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜