在网格视图下方设置两个按钮

时间:2016-10-14 05:47:49

标签: android xml android-layout android-studio

其实我想设置网格视图下面的两个按钮,我尝试相对布局和其他东西,但问题不解决

XML代码:

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/widget"
    android:layout_height="match_parent">
    <include layout="@layout/toolbar"
        android:id="@+id/toolbar">
    </include>
    <GridView
        android:id="@+id/gridView1"
        android:layout_width="363dp"
        android:layout_height="442dp"
        android:columnWidth="90dp"
        android:gravity="bottom"
        android:layout_weight="1"
        android:layout_marginTop="70dp"
        android:layout_below="@+id/toolbar"
        android:horizontalSpacing="0dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="0dp"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp"></GridView>



</android.support.design.widget.CoordinatorLayout>

enter image description here

4 个答案:

答案 0 :(得分:1)

试着希望这可以帮助你..

<RelativeLayout 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"
tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/rlListChariTrust"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ll"
    android:orientation="vertical">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <GridView
            android:id="@+id/gridView1"
            android:layout_width="363dp"
            android:layout_height="442dp"
            android:layout_below="@+id/toolbar"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="0dp"
            android:layout_marginTop="70dp"
            android:layout_weight="1"
            android:columnWidth="90dp"
            android:gravity="bottom"
            android:horizontalSpacing="0dp"
            android:numColumns="2"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />

    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

    <Button
        android:id="@+id/btn1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="bt1" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="bt2" />

</LinearLayout></RelativeLayout>

答案 1 :(得分:1)

以这种方式向网格视图添加页脚可以更有效地管理它,您可以像这样添加页脚。

创建一个要添加到gridview底部的布局并执行此操作

View footerView = (LayoutInflater.from(this).inflate(R.layout.footer_layout, null, false);
GridView.addFooterView(footerView);

这可以解决您的问题。

答案 2 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!--add ur tool bar here -->

<!--gride view -->
<GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/linearLayout"
    android:background="@color/colorAccent"></GridView>

<!--two buttons in LinLay-->
<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <!--button 1-->
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="button 1" />

    <!--button 2-->
    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Buttodddn 2" />

</LinearLayout>

</RelativeLayout>

答案 3 :(得分:0)

enter image description here     

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         android:id="@+id/gridlayout"

        android:layout_above="@+id/linear">

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

        <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:layout_weight="1" />

        <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button"
            android:layout_weight="1" />
    </LinearLayout>
</RelativeLayout>