线性布局中的浮动动作按钮不显示。

问题描述 投票:-1回答:1

你好,我想把一个浮动的操作按钮调整到屏幕的右下角,但它显示在屏幕的右上角,我该怎么做才能让它到右下角?

<?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>
android android-linearlayout
1个回答
0
投票

已对您的UI做了必要的修改,现在可以完美地工作了。

<?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

© www.soinside.com 2019 - 2024. All rights reserved.