0
我想向我的gridview添加一个按钮,但它不起作用。我尝试使用android:layout_weight="1"
,但按钮始终显示,并且我只想在gridview没有任何项目显示时显示按钮。谢谢。无法在GridView下添加按钮
我来源:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<GridView
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/grid" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comprar"
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:background="@drawable/button_shape_red_small"/>
</LinearLayout>
您了解“layout_weight”参数eter是错误的。如果一件商品有重量,而其他商品都是包装内容,则加权商品的尺寸将填充所有剩余的空间,而包裹内容的商品将占用其所需的空间。如果你想在网格已满的情况下移除按钮,请使用JozeRi的答案。 –