Android:布局在gridview的底部(在它的末尾)
我想要的是让 gridview 填满整个屏幕。当你向下滚动时,最后会出现一个带有 2 个按钮的布局。我一直在阅读但不知道如何获得它。我可以将其修复在屏幕顶部和底部(在网格视图上方)。当网格视图被填充时,尝试使用按钮进行布局甚至不会出现。
我一直在尝试权重、对齐等,但找不到问题所在。继承人的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo">
<GridView android:layout_width="fill_parent"
android:id="@+id/gridView1"
android:layout_height="wrap_content"
android:numColumns="2"
android:listSelector="#00000000">
</GridView>
<LinearLayout android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_below="@id/gridView1">
<ImageView android:id="@+id/botonAtras"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="onBotonAtrasClick">
</ImageView>
<ImageView android:id="@+id/botonAdelante"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="onBotonAdelanteClick">
</ImageView>
</LinearLayout>
</RelativeLayout>
What i want is to have the gridview filling whole screen. And when you scroll it down, at the end would appear a layout with 2 buttons. Ive been reading and couldnt figure how to get it. I could fix it on the top of the screen and the bottom (over the gridview). And also trying the layout with the button wont even appear when the gridview is filled.
Ive been playing with weights, aligns, etc. But cant find whats wrong. Heres the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo">
<GridView android:layout_width="fill_parent"
android:id="@+id/gridView1"
android:layout_height="wrap_content"
android:numColumns="2"
android:listSelector="#00000000">
</GridView>
<LinearLayout android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_below="@id/gridView1">
<ImageView android:id="@+id/botonAtras"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="onBotonAtrasClick">
</ImageView>
<ImageView android:id="@+id/botonAdelante"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="onBotonAdelanteClick">
</ImageView>
</LinearLayout>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,你很难做到这一点。您可以使用
addFooter()
使用普通的ListView
来完成此操作,但遗憾的是GridView
没有此方法。此外,您无法实现自己的 GridView,因为它使用了大量私有 API。然而,这里使用了一个可怕的黑客可能会起作用:Android Pull to刷新
显然它使用包含标题视图和 ListView 的
LinearLayout
并移动它们。 (根据此页面。)正如那个人所说,为了一个可怕的黑客攻击需要做很多工作。我能想到的唯一其他方法是放弃 GridView 并使用每行都是水平的 LinearLayout 的 ListView 。不过还是很老套。
As far as I can tell you can't easily do this. You can do it with a plain
ListView
usingaddFooter()
, but sadlyGridView
doesn't have this method. Also you can't implement your ownGridView
because it uses a lot of private APIs.However, there is a horrible hack used here that might work:Android Pull to refresh
Apparently it uses a
LinearLayout
containing the header view and theListView
and moves them both. (According to this page.) As that guy says, a lot of work for a horrible horrible hack.The only other way I can think to do it, is to give up on
GridView
and use aListView
where each row is a horizontalLinearLayout
. Still very hacky though.通过在 id/linearLayout 内设置 android:layout_below:"@+id/gridView" 将 LinearLayout 设置在 GridView 下方
set LinearLayout below GridView by setting android:layout_below:"@+id/gridView" inside id/linearLayout
我这样解决这个问题:
在线性布局中包含GridView,然后我就可以按照你的方式工作。
I solve this problem like this:
include GridView in linearlayout,then i's work as you like.