0

我正在使用带有布局充气器的 gridview 来显示带有文本的图标,不同之处在于我必须在屏幕底部提供一个按钮。我的布局文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
  <merge xmlns:android="http://schemas.android.com/apk/res/android">
 <GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sdcard" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp" android:numColumns="3"
    android:stretchMode="columnWidth" android:gravity="center"  android:background="#ffffff"/>
 <RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button android:text="submit" android:id="@+id/button"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" android:paddingTop="5dp">
    </Button>

</RelativeLayout>
 </merge>

当我在模拟器上测试时(根据真实设备的大小)。网格视图已正确填充,但是当我滚动到最后一行时,图像可见,但文本和按钮不妨碍视图。我希望文本也可见。我怎样才能做到这一点?

在此处输入图像描述

4

3 回答 3

5

试试这个新代码我更新了它并检查了............

<?xml version="1.0" encoding="utf-8"?>
  <merge xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout android:id="@+id/rl1" android:layout_width="wrap_content" android:layout_height="wrap_content">
        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/sdcard" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp" android:numColumns="3"
            android:stretchMode="columnWidth" android:gravity="center"  android:background="#ffffff" android:layout_above="@+id/button"/>
        <Button android:layout_width="fill_parent" android:id="@+id/button" android:paddingTop="5dp" android:layout_height="wrap_content" android:text="submit" android:layout_alignParentBottom="true"></Button>
    </RelativeLayout>
 </merge>
于 2011-06-09T10:34:28.487 回答
1

尝试在另一个 RelativeView 中包含您的 gridview 和相对视图

<?xml version="1.0" encoding="utf-8"?>   
<merge  xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeView xmlns:android="http://schemas.android.com/apk/res/android"            android:id="@+id/outer_container" >   <GridView          android:id="@+id/sdcard" android:layout_width="fill_parent"     android:layout_height="fill_parent" android:verticalSpacing="10dp"     android:horizontalSpacing="10dp" android:numColumns="3"     android:stretchMode="columnWidth" android:gravity="center"  android:background="#ffffff"/>  <RelativeLayout android:layout_width="match_parent"     android:layout_height="match_parent" android:layout_alignBelow="id/sdcard">  <Button android:text="submit" android:id="@+id/button"     android:layout_width="fill_parent" android:layout_height="wrap_content"             android:layout_alignParentBottom="true" android:paddingTop="5dp">         </Button>  
</RelativeLayout>
</RelativeLayout> 
</merge>

或者您可以简单地将 GridView 和您的按钮放入一个 RelativeView

于 2011-06-09T10:32:28.020 回答
0

像这样使用 ConstraintLayout

<GridView
    android:id="@+id/grid_view"
    android:padding="0dp"
    android:columnWidth="90dp"
    android:gravity="center"
    android:horizontalSpacing="10dp"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:verticalSpacing="50dp"
    android:layout_marginBottom="1dp"
    android:layout_width="368dp"
    android:layout_height="551dp"
    tools:layout_editor_absoluteY="8dp"
    tools:layout_editor_absoluteX="8dp" />

于 2016-12-01T10:35:22.793 回答