【问题标题】:How to best fit a customview of Floating Action Button together with Listview如何最适合浮动操作按钮的自定义视图和 Listview
【发布时间】:2016-11-15 17:09:23
【问题描述】:

我有一个带有edittext listview的XML布局和一个包含在一个线性布局中的fab,它在屏幕上占据了很大一部分,如果我减轻重量或使用它,我会得到一个非常小的按钮或裁剪。

<?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"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent">

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/inputSearch"
    android:hint="Αναζητηση" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_margin="4dp">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listCustomers"
        android:layout_margin="5dp"
        android:dividerHeight="2dp" />
</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="2"
    android:layout_gravity="bottom|center"
    android:gravity="right"
    android:layout_margin="4dp">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:id="@+id/fab"
        app:backgroundTint="@android:color/holo_orange_light"
        android:layout_gravity="bottom|center"
        android:layout_margin="10dp"
        android:src="@drawable/ic_action_cross" />
</LinearLayout>

我怎样才能在这里最适合这三个元素?

【问题讨论】:

    标签: android xml android-layout listview floating-action-button


    【解决方案1】:

    将您的完整布局替换为以下内容:

    <?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <EditText
        android:id="@+id/inputSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Αναζητηση"
        android:inputType="textPersonName" />
    
    <ListView
        android:id="@+id/listCustomers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/inputSearch"
        android:layout_margin="9dp"
        android:dividerHeight="2dp" />
    
    
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_margin="14dp"
        android:src="@drawable/ic_action_cross"
        app:backgroundTint="@android:color/holo_orange_light" />
    </RelativeLayout>
    

    【讨论】:

    • 是的,看起来不错,但是 fab 按钮覆盖了 listview 项的文本和图像按钮
    • 只需将 android:layout_below="@+id/listCustomers" 添加到 FloatActionButton 并不会覆盖它们。
    猜你喜欢
    • 2019-12-15
    • 2015-05-24
    • 1970-01-01
    • 2020-05-11
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多