GridView(布局充气器)中的显示问题在屏幕底部有按钮?

发布于 2024-11-14 19:13:31 字数 1123 浏览 3 评论 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>

当我在模拟器上测试它时(大小根据真实设备而定)。网格视图已正确填充,但当我滚动到最后一行时,图像可见,但文本和按钮阻碍了视图。我希望文本也可见。我怎样才能实现这个目标?

在此处输入图像描述

I am using gridview with layout inflator to display icon with text with the difference that I have to provide a button at the bottom of the screen. My layout file looks like this:

<?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>

When I test it on the emulator (size according to the real device). Grid view is correctly populated but when I scroll to the last row the image is visible but not the text and button is hindering the view. I want the text to visible also. How can I achieve this?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野の 2024-11-21 19:13:31

尝试这个新代码我更新了它并也检查了…………

<?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>

Try This New Code I updated it and Checked also .........

<?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>
姐不稀罕 2024-11-21 19:13:31

尝试将您的 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 和您的按钮放入一个相对视图中

Try to include both your gridview and the relative view in another RelativeView

<?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>

OR you can simply put both the GridView and your button into one RelativeView

暖风昔人 2024-11-21 19:13:31

使用约束布局
像这样

<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" />

Use ConstraintLayout
Like this

<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" />

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文