linearlayout中的浮动操作按钮未显示

时间:2020-04-30 18:54:35

标签: android android-linearlayout

您好,我正在尝试将浮动操作按钮对准屏幕的右下角,但是它显示在屏幕的右上角,我该怎么做才能使其右下角?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:theme="@style/AppTheme"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/createRoomButton"
        style="@style/Widget.MaterialComponents.FloatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        app:srcCompat="@drawable/ic_add_black_24dp"/>

    <SearchView
        android:id="@+id/searchInput"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false"
        android:queryHint="Search Rooms">
        <requestFocus />
    </SearchView>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/pullToRefresh"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/roomList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>






</LinearLayout>

1 个答案:

答案 0 :(得分:0)

已经为您的用户界面进行了必要的更改,现在可以完美运行:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:theme="@style/AppTheme"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/createRoomButton"
        style="@style/Widget.MaterialComponents.FloatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="22dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        app:srcCompat="@drawable/ic_add_black_24dp"/>



    <SearchView
        android:id="@+id/searchInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false"
        android:layout_marginTop="50dp"
        android:queryHint="Search Rooms">
        <requestFocus />
    </SearchView>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/pullToRefresh"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/roomList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    </RelativeLayout>
    </LinearLayout>

enter image description here

相关问题