工具栏重叠线性布局的GridView,因此第一行中超过80%的内容被其上方的工具栏隐藏。
我在FloatingActionButton
中添加了activity_main
后发生了这种情况。我试图在LinearLayout中包含工具栏,但它给了我一个强制转换异常。如果可以在LinearLayout中包含工具栏,我很好。另外,我尝试使用marginTop
或paddingTop
静态处理它。
以下是它现在的样子:Screenshot
以下是xml文件:
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="edu.ahduni.seas.gyapak.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/textlayout"
tools:context="edu.ahduni.seas.gyapak.MainActivity">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:padding="10dp" />
</LinearLayout>
解
显然,有很多解决方案:(信用转到答案和评论讨论)
1。在android:layout_marginTop="?attr/actionBarSize"
的LinearLayout中包含android:paddingTop="AnydpThatYouFurtherWantToAdjust"
content_main.xml
来自:@VladimirJovanović
2。包括app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingTop="AnydpThatYouFurtherWantToAdjust"
的LinearLayout中的content_main.xml
来自:@Burhanuddin Rashid
3。这是一个很长的问题,请查看@ AbhayBohra的答案,然后将android:paddingTop="AnydpThatYouFurtherWantToAdjust"
包含在content_main.xml
Credit的LinearLayout中:@Abhay Bohra和@Rahul Sharma
答案 0 :(得分:2)
尝试在具有垂直方向的LinearLayout中添加appBarLayout和include语句
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="edu.ahduni.seas.gyapak.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:1)
将Connection conn;
Statement st;
ResultSet rs;
public void Connect() throws SQLException
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bookcase", "root", "1234");
if(conn.isValid(10))
{
System.out.println("Connection reached");
}
else
{
System.out.println("Something went wrong!");
}
}
添加到您的content_main <!channel>
,如下所示:
app:layout_behavior
答案 2 :(得分:0)
尝试将tools:showIn="@layout/activity_main"
添加到content_main.xml
LinearLayout。
最终代码应如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/textlayout"
tools:showIn="@layout/activity_main"
tools:context="edu.ahduni.seas.gyapak.MainActivity">