gpt4 book ai didi

android - 如何对齐 Android 中 GridView 顶部的项目?

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:25 26 4
gpt4 key购买 nike

我尝试制作自己的画廊应用程序。问题是我的 ImageView 出现在包含它们的 GridView 的底部。如何在顶部对齐它们?我试过设置重力,但没用。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/crud_layout" >

<GridView
android:id="@+id/album_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="100dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />

</FrameLayout>

<LinearLayout
android:id="@id/crud_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >

<Button
android:id="@+id/button_share"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/new_album" />

<Button
android:id="@+id/button_delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/delete_album" />

<ImageButton
android:id="@+id/button_camera"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</ImageButton>
</LinearLayout>

最佳答案

如下所示编辑您的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:layout_alignParentTop="true"**//change only here
android:layout_above="@+id/crud_layout" >

<GridView
android:id="@+id/album_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="100dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />

</FrameLayout>

<LinearLayout
android:id="@id/crud_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >

<Button
android:id="@+id/button_share"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="zee" />

<Button
android:id="@+id/button_delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="khan" />

<ImageButton
android:id="@+id/button_camera"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</ImageButton>
</LinearLayout>
</RelativeLayout>

关于android - 如何对齐 Android 中 GridView 顶部的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23028274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com