如何在Toolbar下完美设置GridView。我想要的是在所有设备。这该怎么做?margin
"0dp"
我尝试过设置,marginTop
但在带有大屏幕GridView的设备上覆盖了Toolbar。它在各个设备上看起来不同。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="MainActivity">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="#000000"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="Application"/>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:layout_marginTop="56dp"
android:horizontalSpacing="8dp"
android:numColumns="2"
android:verticalSpacing="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"></GridView>
</android.support.constraint.ConstraintLayout>
您可以使用相对布局。在相对布局中,放置工具栏和 GridView。
在 GridView 中,写下这一行:
android:layout_below="@id/toolbar"
它会将 GridView 放在工具栏下方。
像这样 :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="#000000"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="Application"/>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_below="@id/toolbar"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:horizontalSpacing="8dp"
android:numColumns="2"
android:verticalSpacing="8dp"></GridView>
</RelativeLayout>
您有 2 个选择:
1)您可以简单地将此代码发布到您的约束布局中,并在 RelativeLayout 中键入您想要的命令(与约束布局有关)
2)直接用RelativeLayout替换ConstraintLayout(这种情况我推荐你这个方法,这样更容易编码)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句