ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 隐藏在ToolBar后面的ListView,以及隐藏在ListView后面的浮动操作按钮

2019-07-06 02:24:50  阅读:93  来源: 互联网

标签:android listview floating-action-button


我的FAB将显示在android studio的设计窗口中,但在我实际运行应用程序时不显示.

另外,我有一个ListView项目,我指定它应该位于工具栏下方,但是当我运行应用程序时,它部分隐藏在工具栏后面.

<?xml version="1.0" encoding="utf-8"?>

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

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />

<at.markushi.ui.CircleButton
    android:layout_width="64dp"
    android:layout_height="64dp"
    app:cb_color="@color/colorPrimary"
    app:cb_pressedRingWidth="8dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:onClick="openEditorForNewNote"
    android:src="@drawable/ic_action_add"/>

</RelativeLayout>

how the layout appears in design mode

how app appears when run

做什么?

解决方法:

My FAB will shows up in the design window in android studio but does not show up when I actually run the app.

尝试在代码中将FAB移动到ListView上方,如下所示:

<?xml version="1.0" encoding="utf-8"?>

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

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<at.markushi.ui.CircleButton
    android:layout_width="64dp"
    android:layout_height="64dp"
    app:cb_color="@color/colorPrimary"
    app:cb_pressedRingWidth="8dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:onClick="openEditorForNewNote"
    android:src="@drawable/ic_action_add"/>

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />
</RelativeLayout>

基本上,Android会根据XML标记中的顺序以特定顺序呈现布局.

In addition, I have a ListView item which I have specified should sit below the toolbar, yet when I run the app it is partially hidden behind the toolbar.

将listView的高度更改为wrap_content(我在上面的代码中将其更改为如此,但这里又是):

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />

因为ListView是工具栏的兄弟,所以当高度设置为match_parent时,它会填满整个屏幕,包括工具栏下的区域.

标签:android,listview,floating-action-button
来源: https://codeday.me/bug/20190706/1393261.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有